3091: 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/debug/iota.spe.hh, * mln/debug/put_word.hh, * mln/debug/println.spe.hh, * mln/core/site_set/box.hh, * mln/core/site_set/box_piter.hh, * mln/core/image/image1d.hh, * mln/core/image/image2d.hh, * mln/core/image/image3d.hh, * mln/core/point.hh, * mln/core/box_runstart_piter.hh, * mln/core/alias/window2d.hh, * mln/core/concept/site_set.hh, * mln/core/dpoint.hh, * mln/math/abs.hh, * mln/opt/at.hh, * mln/accu/sum.hh, * mln/accu/line.hh, * mln/accu/mean.hh, * mln/value/float01_.hh, * mln/value/int_s.hh, * mln/value/int_u.hh, * mln/value/float01.hh, * mln/make/win_chamfer.hh, * mln/make/image.hh, * mln/make/box2d_h.hh, * mln/make/point2d_h.hh, * mln/make/dpoint2d_h.hh, * mln/make/box1d.hh, * mln/make/box2d.hh, * mln/make/box3d.hh, * mln/border/mirror.hh, * mln/convert/to_image.hh, * mln/win/line.hh, * mln/win/diag2d.hh, * mln/win/backdiag2d.hh, * mln/win/octagon2d.hh, * mln/win/disk2d.hh, * mln/algebra/mat.hh, * mln/algebra/h_vec.hh, * mln/algebra/vec.hh, * mln/io/pnm/save_header.hh, * mln/io/pnm/load_header.hh, * mln/io/pnm/save.hh, * mln/io/pnm/load.hh, * mln/io/pbm/save.hh, * tests/data/fill.cc, * tests/border/fill_full.cc, * tests/convert/to_p_array.cc, * tests/convert/to_image.cc, * tests/win/diag2d.cc: Use static_cast. Replace int by def::coord when needed. mln/accu/line.hh | 8 ++--- mln/accu/mean.hh | 8 +++-- mln/accu/sum.hh | 2 - mln/algebra/h_vec.hh | 10 +++--- mln/algebra/mat.hh | 17 +++++------ mln/algebra/vec.hh | 21 ++++++++------ mln/border/mirror.hh | 15 ++++++---- mln/convert/to_image.hh | 1 mln/core/alias/window2d.hh | 21 +++++++++----- mln/core/box_runstart_piter.hh | 15 +++++----- mln/core/concept/site_set.hh | 10 ------ mln/core/dpoint.hh | 3 +- mln/core/image/image1d.hh | 11 ++++--- mln/core/image/image2d.hh | 14 +++++---- mln/core/image/image3d.hh | 16 ++++++---- mln/core/point.hh | 4 +- mln/core/site_set/box.hh | 18 ++++++------ mln/core/site_set/box_piter.hh | 2 - mln/debug/iota.spe.hh | 2 - mln/debug/println.spe.hh | 14 +++++---- mln/debug/put_word.hh | 13 ++++---- mln/io/pbm/save.hh | 33 +++++++++++----------- mln/io/pnm/load.hh | 16 ++++------ mln/io/pnm/load_header.hh | 2 - mln/io/pnm/save.hh | 22 ++++++--------- mln/io/pnm/save_header.hh | 16 ++++------ mln/make/box1d.hh | 10 +++--- mln/make/box2d.hh | 8 ++--- mln/make/box2d_h.hh | 21 +++++++------- mln/make/box3d.hh | 12 ++++---- mln/make/dpoint2d_h.hh | 14 ++++----- mln/make/image.hh | 20 +++++++++---- mln/make/point2d_h.hh | 14 ++++----- mln/make/win_chamfer.hh | 58 +++++++++++++++++++-------------------- mln/math/abs.hh | 9 ++---- mln/opt/at.hh | 60 ++++++++++++++++++++--------------------- mln/value/float01.hh | 12 ++++---- mln/value/float01_.hh | 13 +++++--- mln/value/int_s.hh | 17 ++++++----- mln/value/int_u.hh | 4 +- mln/win/backdiag2d.hh | 14 +++++---- mln/win/diag2d.hh | 17 ++++++----- mln/win/disk2d.hh | 20 +++++++------ mln/win/line.hh | 6 ++-- mln/win/octagon2d.hh | 57 +++++++++++++++++++++++--------------- tests/border/fill_full.cc | 8 ++--- tests/convert/to_image.cc | 1 tests/convert/to_p_array.cc | 10 ++++-- tests/data/fill.cc | 20 +++++-------- tests/win/diag2d.cc | 17 +++++------ 50 files changed, 402 insertions(+), 354 deletions(-) Index: mln/debug/iota.spe.hh --- mln/debug/iota.spe.hh (revision 3090) +++ mln/debug/iota.spe.hh (working copy) @@ -63,7 +63,7 @@ unsigned i = 0; mln_pixter(I) p(input); for_all(p) - p.val() = ++i % mln_max(mln_value(I)); + p.val() = static_cast<mln_value(I)>(++i % mln_max(mln_value(I))); } # endif // ! MLN_INCLUDE_ONLY Index: mln/debug/put_word.hh --- mln/debug/put_word.hh (revision 3090) +++ mln/debug/put_word.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_DEBUG_PUT_WORD_HH # define MLN_DEBUG_PUT_WORD_HH -/*! \file mln/debug/put_word.hh - * - * \brief Write a word in a 2D image of characters. - */ +/// \file mln/debug/put_word.hh +/// +/// Write a word in a 2D image of characters. # include <string> # include <mln/core/image/image2d.hh> @@ -62,7 +61,9 @@ mln_precondition(inout.has(word_start)); point2d word_end = word_start; - word_end.last_coord() += word.length() - 1; + + word_end.last_coord() = static_cast<def::coord>(word_end.last_coord() + word.length() - 1); + if (!inout.has(word_end)) trace::warning("Cannot write text outside the image domain"); Index: mln/debug/println.spe.hh --- mln/debug/println.spe.hh (revision 3090) +++ mln/debug/println.spe.hh (working copy) @@ -84,9 +84,9 @@ void println(const box2d& b, const image2d<char>& input) { - for (int row = b.min_row(); row <= b.max_row(); ++row) + for (def::coord row = b.min_row(); row <= b.max_row(); ++row) { - for (int col = b.min_col(); col <= b.max_col(); ++col) + for (def::coord col = b.min_col(); col <= b.max_col(); ++col) std::cout << opt::at(input, row, col) << ' '; std::cout << std::endl; } @@ -115,14 +115,16 @@ { std::ostringstream oss; oss << format(input(p)); - point2d w( p.row() - b.min_row(), - (p.col() - b.min_col()) * len); + def::coord + row = static_cast<def::coord>(p.row() - b.min_row()), + col = static_cast<def::coord>((p.col() - b.min_col()) * len); + point2d w(row, col); put_word(output, w, oss.str()); } - for (unsigned row = 0; row < b.nrows(); ++row) + for (def::coord row = 0; row < def::coord(b.nrows()); ++row) { - for (unsigned col = 0; col < b.ncols() * len; ++col) + for (def::coord col = 0; col < def::coord(b.ncols() * len); ++col) std::cout << opt::at(output, row, col); std::cout << std::endl; } Index: mln/core/site_set/box.hh --- mln/core/site_set/box.hh (revision 3090) +++ mln/core/site_set/box.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_CORE_SITE_SET_BOX_HH # define MLN_CORE_SITE_SET_BOX_HH -/*! \file mln/core/site_set/box.hh - * - * \brief This file defines a generic box class. - * - * \todo Test if the safety code in box::box() is not too slow. - */ +/// \file mln/core/site_set/box.hh +/// +/// This file defines a generic box class. +/// +/// \todo Test if the safety code in box::box() is not too slow. # include <mln/core/concept/box.hh> # include <mln/core/internal/box_impl.hh> @@ -357,8 +357,8 @@ for (unsigned i = 0; i < P::dim; ++i) { - tmp.pmin_[i] -= b; - tmp.pmax_[i] += b; + tmp.pmin_[i] = static_cast<mln_coord(P)>(tmp.pmin_[i] - b); + tmp.pmax_[i] = static_cast<mln_coord(P)>(tmp.pmax_[i] + b); } mln_postcondition(tmp.is_valid()); return tmp; @@ -372,7 +372,7 @@ mln_precondition(is_valid()); P center; for (unsigned i = 0; i < P::dim; ++i) - center[i] = pmin_[i] + ((pmax_[i] - pmin_[i]) / 2); + center[i] = static_cast<mln_coord(P)>(pmin_[i] + ((pmax_[i] - pmin_[i]) / 2)); return center; } Index: mln/core/site_set/box_piter.hh --- mln/core/site_set/box_piter.hh (revision 3090) +++ mln/core/site_set/box_piter.hh (working copy) @@ -165,7 +165,7 @@ void box_fwd_piter_<P>::invalidate_() { - p_[0] = (s_->pmax()[0] + 1); + p_[0] = static_cast<def::coord>(s_->pmax()[0] + 1); } template <typename P> Index: mln/core/image/image1d.hh --- mln/core/image/image1d.hh (revision 3090) +++ mln/core/image/image1d.hh (working copy) @@ -181,10 +181,10 @@ // ----------------- /// Read-only access to the image value located at (\p index). - const T& at(int index) const; + const T& at(def::coord index) const; /// Read-write access to the image value located at (\p index). - T& at(int index); + T& at(def::coord index); /// Fast Image method @@ -426,7 +426,7 @@ template <typename T> inline const T& - image1d<T>::at(int index) const + image1d<T>::at(def::coord index) const { mln_precondition(this->has(point1d(index))); return this->data_->array_[index]; @@ -435,7 +435,7 @@ template <typename T> inline T& - image1d<T>::at(int index) + image1d<T>::at(def::coord index) { mln_precondition(this->has(point1d(index))); return this->data_->array_[index]; @@ -494,7 +494,8 @@ image1d<T>::point_at_index(unsigned i) const { mln_precondition(i < nelements()); - point1d p = point1d(i + this->data_->vb_.min_ind()); + def::coord ind = static_cast<def::coord>(i + this->data_->vb_.min_ind()); + point1d p = point1d(ind); mln_postcondition(& this->operator()(p) == this->data_->buffer_ + i); return p; } Index: mln/core/image/image2d.hh --- mln/core/image/image2d.hh (revision 3090) +++ mln/core/image/image2d.hh (working copy) @@ -205,10 +205,10 @@ // ----------------- /// Read-only access to the image value located at (\p row, \p col). - const T& at(int row, int col) const; + const T& at(def::coord row, def::coord col) const; /// Read-write access to the image value located at (\p row, \p col). - T& at(int row, int col); + T& at(def::coord row, def::coord col); /// Give the number of rows. unsigned nrows() const; @@ -463,7 +463,7 @@ template <typename T> inline const T& - image2d<T>::at(int row, int col) const + image2d<T>::at(def::coord row, def::coord col) const { mln_precondition(this->has(point2d(row, col))); return this->data_->array_[row][col]; @@ -472,7 +472,7 @@ template <typename T> inline T& - image2d<T>::at(int row, int col) + image2d<T>::at(def::coord row, def::coord col) { mln_precondition(this->has(point2d(row, col))); return this->data_->array_[row][col]; @@ -569,8 +569,10 @@ image2d<T>::point_at_index(unsigned i) const { mln_precondition(i < nelements()); - point2d p = point2d(i / this->data_->vb_.len(1) + this->data_->vb_.min_row(), - i % this->data_->vb_.len(1) + this->data_->vb_.min_col()); + def::coord + row = static_cast<def::coord>(i / this->data_->vb_.len(1) + this->data_->vb_.min_row()), + col = static_cast<def::coord>(i % this->data_->vb_.len(1) + this->data_->vb_.min_col()); + point2d p = point2d(row, col); mln_postcondition(& this->operator()(p) == this->data_->buffer_ + i); return p; } Index: mln/core/image/image3d.hh --- mln/core/image/image3d.hh (revision 3090) +++ mln/core/image/image3d.hh (working copy) @@ -201,11 +201,11 @@ /// Read-only access to the image value located at (\p sli, \p /// row, \p col). - const T& at(int sli, int row, int col) const; + const T& at(def::coord sli, def::coord row, def::coord col) const; /// Read-write access to the image value located at (\p sli, \p /// row, \p col). - T& at(int sli, int row, int col); + T& at(def::coord sli, def::coord row, def::coord col); /// Fast Image method @@ -484,7 +484,7 @@ template <typename T> inline const T& - image3d<T>::at(int sli, int row, int col) const + image3d<T>::at(def::coord sli, def::coord row, def::coord col) const { mln_precondition(this->has(point3d(sli, row, col))); return data_->array_[sli][row][col]; @@ -493,7 +493,7 @@ template <typename T> inline T& - image3d<T>::at(int sli, int row, int col) + image3d<T>::at(def::coord sli, def::coord row, def::coord col) { mln_precondition(this->has(point3d(sli, row, col))); return data_->array_[sli][row][col]; @@ -533,9 +533,11 @@ image3d<T>::point_at_index(unsigned o) const { mln_precondition(o < nelements()); - point3d p = point3d(o / (data_->vb_.len(1) * data_->vb_.len(2)) + data_->vb_.min_sli(), - (o % (data_->vb_.len(1) * data_->vb_.len(2))) / data_->vb_.len(2) + data_->vb_.min_row(), - o % data_->vb_.len(2) + data_->vb_.min_col()); + def::coord + sli = static_cast<def::coord>(o / (data_->vb_.len(1) * data_->vb_.len(2)) + data_->vb_.min_sli()), + row = static_cast<def::coord>((o % (data_->vb_.len(1) * data_->vb_.len(2))) / data_->vb_.len(2) + data_->vb_.min_row()), + col = static_cast<def::coord>(o % data_->vb_.len(2) + data_->vb_.min_col()); + point3d p = point3d(sli, row, col); mln_postcondition(& this->operator()(p) == this->data_->buffer_ + o); return p; } Index: mln/core/point.hh --- mln/core/point.hh (revision 3090) +++ mln/core/point.hh (working copy) @@ -298,7 +298,7 @@ mlc_converts_to(mln_result(F), C)::check(); const F& f = exact(f_); for (unsigned i = 0; i < dim; ++i) - coord_[i] = f(i); + coord_[i] = static_cast<C>( f(i) ); } template <typename G, typename C> @@ -369,7 +369,7 @@ point<G,C>::operator+=(const delta& dp) { for (unsigned i = 0; i < dim; ++i) - coord_[i] += dp[i]; + coord_[i] = static_cast<C>(coord_[i] + dp[i]); return *this; } Index: mln/core/box_runstart_piter.hh --- mln/core/box_runstart_piter.hh (revision 3090) +++ mln/core/box_runstart_piter.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,18 +29,18 @@ #ifndef MLN_CORE_BOX_RUNSTART_PITER_HH # define MLN_CORE_BOX_RUNSTART_PITER_HH -/*! \file mln/core/box_runstart_piter.hh - * - * \brief Definition of iterators on points by lines. - * - */ +/// \file mln/core/box_runstart_piter.hh +/// +/// Definition of iterators on points by lines. # include <mln/core/internal/site_iterator_base.hh> # include <mln/core/site_set/box.hh> + #define mln_box_runstart_piter(I) typename mln::box_runstart_piter< mln_psite(I) > #define mln_box_runstart_piter_(I) mln::box_runstart_piter<mln_psite(I)> + namespace mln { @@ -111,7 +112,7 @@ bool box_runstart_piter<P>::is_valid_() const { - return p_[0] != s_->pmax()[0] + 1; + return p_[0] != static_cast<mln_coord(P)>(s_->pmax()[0] + 1); } template <typename P> @@ -119,7 +120,7 @@ void box_runstart_piter<P>::invalidate_() { - p_[0] = s_->pmax()[0] + 1; + p_[0] = static_cast<mln_coord(P)>(s_->pmax()[0] + 1); } template <typename P> Index: mln/core/alias/window2d.hh --- mln/core/alias/window2d.hh (revision 3090) +++ mln/core/alias/window2d.hh (working copy) @@ -107,12 +107,15 @@ void from_to_(const bool (&values)[S], window2d& win) { - enum { h = mlc_sqrt_int(S) / 2 }; - mlc_bool((2 * h + 1) * (2 * h + 1) == S)::check(); + enum { H = mlc_sqrt_int(S) / 2 }; + mlc_bool((2 * H + 1) * (2 * H + 1) == S)::check(); win.clear(); unsigned i = 0; - for (int row = - h; row <= h; ++row) - for (int col = - h; col <= h; ++col) + const def::coord + h = static_cast<def::coord>(H), + _h = static_cast<def::coord>(-h); + for (def::coord row = _h; row <= h; ++row) + for (def::coord col = _h; col <= h; ++col) if (values[i++]) win.insert(row, col); } @@ -124,9 +127,13 @@ mlc_bool(R % 2 == 1)::check(); mlc_bool(C % 2 == 1)::check(); win.clear(); - const int drow = int(R) / 2, dcol = int(C) / 2; - for (int row = - drow; row <= drow; ++row) - for (int col = - dcol; col <= dcol; ++col) + const def::coord + drow = static_cast<def::coord>(R / 2), + _drow = static_cast<def::coord>(- drow), + dcol = static_cast<def::coord>(C / 2), + _dcol = static_cast<def::coord>(- dcol); + for (def::coord row = _drow; row <= drow; ++row) + for (def::coord col = _dcol; col <= dcol; ++col) if (values[row + drow][col + dcol]) win.insert(row, col); } Index: mln/core/concept/site_set.hh --- mln/core/concept/site_set.hh (revision 3090) +++ mln/core/concept/site_set.hh (working copy) @@ -48,17 +48,9 @@ namespace mln { - // Forward declarations. + // Forward declaration. template <typename E> struct Site_Set; - namespace convert - { - - template <typename F, typename T> - void from_to(const F& from, T& to); - - } - /// Site_Set category flag type. template <> Index: mln/core/dpoint.hh --- mln/core/dpoint.hh (revision 3090) +++ mln/core/dpoint.hh (working copy) @@ -40,6 +40,7 @@ # include <mln/algebra/vec.hh> # include <mln/metal/converts_to.hh> + namespace mln { @@ -232,7 +233,7 @@ mlc_converts_to(mln_result(F), C)::check(); const F& f = exact(f_); for (unsigned i = 0; i < dim; ++i) - coord_[i] = f(i); + coord_[i] = static_cast<C>(f(i)); } template <typename G, typename C> Index: mln/math/abs.hh --- mln/math/abs.hh (revision 3090) +++ mln/math/abs.hh (working copy) @@ -29,10 +29,9 @@ #ifndef MLN_MATH_ABS_HH # define MLN_MATH_ABS_HH -/*! \file mln/math/abs.hh - * - * \brief Define the absolute value (abs) routine. - */ +/// \file mln/math/abs.hh +/// +/// Define the absolute value (abs) routine. # include <cmath> # include <cstdlib> @@ -77,7 +76,7 @@ inline T abs(const T& v) { - return v >= 0 ? v : -v; + return v >= 0 ? v : static_cast<T>(-v); } inline int abs(int v) { return std::abs(v); } Index: mln/opt/at.hh --- mln/opt/at.hh (revision 3090) +++ mln/opt/at.hh (working copy) @@ -49,25 +49,25 @@ /// One dimension template <typename I> - mln_rvalue(I) at(const Image<I>& ima, int ind); + mln_rvalue(I) at(const Image<I>& ima, def::coord ind); template <typename I> - mln_lvalue(I) at(Image<I>& ima, int ind); + mln_lvalue(I) at(Image<I>& ima, def::coord ind); /// Two dimensions template <typename I> - mln_rvalue(I) at(const Image<I>& ima, int row, int col); + mln_rvalue(I) at(const Image<I>& ima, def::coord row, def::coord col); template <typename I> - mln_lvalue(I) at(Image<I>& ima, int row, int col); + mln_lvalue(I) at(Image<I>& ima, def::coord row, def::coord col); /// Three dimensions template <typename I> - mln_rvalue(I) at(const Image<I>& ima, int sli, int row, int col); + mln_rvalue(I) at(const Image<I>& ima, def::coord sli, def::coord row, def::coord col); template <typename I> - mln_lvalue(I) at(Image<I>& ima, int sli, int row, int col); + mln_lvalue(I) at(Image<I>& ima, def::coord sli, def::coord row, def::coord col); # ifndef MLN_INCLUDE_ONLY @@ -80,7 +80,7 @@ template <typename I> inline mln_rvalue(I) at_1d_impl(trait::image::category::domain_morpher, - const Image<I>& ima, int ind) + const Image<I>& ima, def::coord ind) { point1d p(ind); return exact(ima)(p); @@ -89,7 +89,7 @@ template <typename I> inline mln_rvalue(I) at_1d_impl(trait::image::category::morpher, - const Image<I>& ima, int ind) + const Image<I>& ima, def::coord ind) { // FIXME: what about morpher that modify the image value? // (through a function for instance) @@ -99,7 +99,7 @@ template <typename I> inline mln_rvalue(I) at_1d_impl(trait::image::category::primary, - const Image<I>& ima, int ind) + const Image<I>& ima, def::coord ind) { return exact(ima).at(ind); } @@ -108,7 +108,7 @@ template <typename I> inline mln_lvalue(I) at_1d_impl(trait::image::category::domain_morpher, - Image<I>& ima, int ind) + Image<I>& ima, def::coord ind) { mlc_is(mln_trait_image_pw_io(I), trait::image::pw_io::read_write)::check(); @@ -120,7 +120,7 @@ template <typename I> inline mln_lvalue(I) at_1d_impl(trait::image::category::morpher, - Image<I>& ima, int ind) + Image<I>& ima, def::coord ind) { // FIXME: what about morpher that modify the image value? // (through a function for instance) @@ -130,7 +130,7 @@ template <typename I> inline mln_lvalue(I) at_1d_impl(trait::image::category::primary, - Image<I>& ima, int ind) + Image<I>& ima, def::coord ind) { return exact(ima).at(ind); } @@ -139,7 +139,7 @@ template <typename I> inline - mln_rvalue(I) at(const Image<I>& ima, int ind) + mln_rvalue(I) at(const Image<I>& ima, def::coord ind) { mlc_is(mln_trait_image_dimension(I), trait::image::dimension::one_d)::check(); @@ -148,7 +148,7 @@ } template <typename I> - mln_lvalue(I) at(Image<I>& ima, int ind) + mln_lvalue(I) at(Image<I>& ima, def::coord ind) { mlc_is(mln_trait_image_dimension(I), trait::image::dimension::one_d)::check(); @@ -165,7 +165,7 @@ template <typename I> inline mln_rvalue(I) at_2d_impl(trait::image::category::domain_morpher, - const Image<I>& ima, int row, int col) + const Image<I>& ima, def::coord row, def::coord col) { point2d p(row, col); return exact(ima)(p); @@ -174,7 +174,7 @@ template <typename I> inline mln_rvalue(I) at_2d_impl(trait::image::category::morpher, - const Image<I>& ima, int row, int col) + const Image<I>& ima, def::coord row, def::coord col) { // FIXME: what about morpher that modify the image value? // (through a function for instance) @@ -184,7 +184,7 @@ template <typename I> inline mln_rvalue(I) at_2d_impl(trait::image::category::primary, - const Image<I>& ima, int row, int col) + const Image<I>& ima, def::coord row, def::coord col) { return exact(ima).at(row, col); } @@ -193,7 +193,7 @@ template <typename I> inline mln_lvalue(I) at_2d_impl(trait::image::category::domain_morpher, - Image<I>& ima, int row, int col) + Image<I>& ima, def::coord row, def::coord col) { mlc_is(mln_trait_image_pw_io(I), trait::image::pw_io::read_write)::check(); @@ -205,7 +205,7 @@ template <typename I> inline mln_lvalue(I) at_2d_impl(trait::image::category::morpher, - Image<I>& ima, int row, int col) + Image<I>& ima, def::coord row, def::coord col) { // FIXME: what about morpher that modify the image value? // (through a function for instance) @@ -215,7 +215,7 @@ template <typename I> inline mln_lvalue(I) at_2d_impl(trait::image::category::primary, - Image<I>& ima, int row, int col) + Image<I>& ima, def::coord row, def::coord col) { return exact(ima).at(row, col); } @@ -224,7 +224,7 @@ template <typename I> inline - mln_rvalue(I) at(const Image<I>& ima, int row, int col) + mln_rvalue(I) at(const Image<I>& ima, def::coord row, def::coord col) { mlc_is(mln_trait_image_dimension(I), trait::image::dimension::two_d)::check(); @@ -233,7 +233,7 @@ } template <typename I> - mln_lvalue(I) at(Image<I>& ima, int row, int col) + mln_lvalue(I) at(Image<I>& ima, def::coord row, def::coord col) { mlc_is(mln_trait_image_dimension(I), trait::image::dimension::two_d)::check(); @@ -249,7 +249,7 @@ template <typename I> inline mln_rvalue(I) at_3d_impl(trait::image::category::domain_morpher, - const Image<I>& ima, int sli, int row, int col) + const Image<I>& ima, def::coord sli, def::coord row, def::coord col) { point3d p(sli, row, col); return exact(ima)(p); @@ -258,7 +258,7 @@ template <typename I> inline mln_rvalue(I) at_3d_impl(trait::image::category::morpher, - const Image<I>& ima, int sli, int row, int col) + const Image<I>& ima, def::coord sli, def::coord row, def::coord col) { // FIXME: what about morpher that modify the image value? // (through a function for instance) @@ -268,7 +268,7 @@ template <typename I> inline mln_rvalue(I) at_3d_impl(trait::image::category::primary, - const Image<I>& ima, int sli, int row, int col) + const Image<I>& ima, def::coord sli, def::coord row, def::coord col) { return exact(ima).at(sli, row, col); } @@ -277,7 +277,7 @@ template <typename I> inline mln_lvalue(I) at_3d_impl(trait::image::category::domain_morpher, - Image<I>& ima, int sli, int row, int col) + Image<I>& ima, def::coord sli, def::coord row, def::coord col) { mlc_is(mln_trait_image_pw_io(I), trait::image::pw_io::read_write)::check(); @@ -289,7 +289,7 @@ template <typename I> inline mln_lvalue(I) at_3d_impl(trait::image::category::morpher, - Image<I>& ima, int sli, int row, int col) + Image<I>& ima, def::coord sli, def::coord row, def::coord col) { // FIXME: what about morpher that modify the image value? // (through a function for instance) @@ -299,7 +299,7 @@ template <typename I> inline mln_lvalue(I) at_3d_impl(trait::image::category::primary, - Image<I>& ima, int sli, int row, int col) + Image<I>& ima, def::coord sli, def::coord row, def::coord col) { return exact(ima).at(sli, row, col); } @@ -308,7 +308,7 @@ template <typename I> inline - mln_rvalue(I) at(const Image<I>& ima, int sli, int row, int col) + mln_rvalue(I) at(const Image<I>& ima, def::coord sli, def::coord row, def::coord col) { mlc_is(mln_trait_image_dimension(I), trait::image::dimension::three_d)::check(); @@ -318,7 +318,7 @@ } template <typename I> - mln_lvalue(I) at(Image<I>& ima, int sli, int row, int col) + mln_lvalue(I) at(Image<I>& ima, def::coord sli, def::coord row, def::coord col) { mlc_is(mln_trait_image_dimension(I), trait::image::dimension::three_d)::check(); Index: mln/accu/sum.hh --- mln/accu/sum.hh (revision 3090) +++ mln/accu/sum.hh (working copy) @@ -123,7 +123,7 @@ inline void sum<T,S>::take(const argument& t) { - s_ += t; + s_ += static_cast<S>(t); } template <typename T, typename S> Index: mln/accu/line.hh --- mln/accu/line.hh (revision 3090) +++ mln/accu/line.hh (working copy) @@ -125,8 +125,8 @@ O& output = exact(output_); // Avoid warning in signed/unsigned comparison. - const def::coord len = len_; - const def::coord half_length = half_length_; + const def::coord len = static_cast<def::coord>(len_); + const def::coord half_length = static_cast<def::coord>(half_length_); // Checks and tests. internal::line_tests<Meta_Accu, Dir>(input, @@ -136,7 +136,7 @@ // Initialization. const def::coord start = p_start[Dir]; - const def::coord last = start + len - 1; + const def::coord last = static_cast<def::coord>(start + len - 1); A a; // Accumulator. a.init(); P p; // Current point. @@ -159,7 +159,7 @@ P p_plus = p_start; def::coord& plus = p_plus[Dir]; - plus += half_length; + plus = static_cast<def::coord>(plus + half_length); while (cur < start + half_length && cur < last) { Index: mln/accu/mean.hh --- mln/accu/mean.hh (revision 3090) +++ mln/accu/mean.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 @@ -149,14 +150,15 @@ M mean<T,S,M>::to_result() const { - return sum_.to_result() / count_.to_result(); + S n = static_cast<S>(count_.to_result()); + return static_cast<M>(sum_.to_result() / n); } template <typename T, typename S, typename M> inline mean<T,S,M>::operator M() const { - return M(sum_.to_result() / count_.to_result()); + return to_result(); } template <typename T, typename S, typename M> Index: mln/value/float01_.hh --- mln/value/float01_.hh (revision 3090) +++ mln/value/float01_.hh (working copy) @@ -113,6 +113,9 @@ /// Conversion to a float. operator float() const; + + private: + typedef mln_enc(int_u<n>) enc_; }; @@ -166,7 +169,7 @@ { mln_precondition(val >= 0); mln_precondition(val <= 1); - this->v_ = int(val * (mln_card(float01_<n>) - 1)); // FIXME + this->v_ = static_cast<enc_>(val * (mln_card(float01_<n>) - 1)); // FIXME } template <unsigned n> @@ -174,7 +177,7 @@ float float01_<n>::value() const { - return float(this->v_) / (mln_card(float01_<n>) - 1); // FIXME + return float(this->v_) / float(mln_card(float01_<n>) - 1); // FIXME } template <unsigned n> @@ -182,7 +185,7 @@ void float01_<n>::set_ind(unsigned long val) { - this->v_ = val; + this->v_ = static_cast<enc_>(val); } template <unsigned n> @@ -192,7 +195,7 @@ { mln_precondition(val >= 0); mln_precondition(val <= 1); - this->v_ = int(val * (mln_card(float01_<n>) - 1)); // FIXME + this->v_ = static_cast<enc_>(val * (mln_card(float01_<n>) - 1)); // FIXME return *this; } @@ -200,7 +203,7 @@ inline float01_<n>::operator float() const { - return float(this->v_) / (mln_card(float01_<n>) - 1); + return float(this->v_) / float(mln_card(float01_<n>) - 1); } Index: mln/value/int_s.hh --- mln/value/int_s.hh (revision 3090) +++ mln/value/int_s.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_INT_S_HH # define MLN_VALUE_INT_S_HH -/*! \file mln/value/int_s.hh - * - * \brief Define a generic class for signed integers. - */ +/// \file mln/value/int_s.hh +/// +/// Define a generic class for signed integers. # include <mln/value/ops.hh> @@ -139,6 +139,9 @@ /// Unit value. static const int_s<n> one; + + private: + typedef typename internal::encoding_signed_<n>::ret enc_; }; @@ -184,7 +187,7 @@ static const int min = - max; mln_precondition(i >= min); mln_precondition(i <= max); - this->v_ = i; + this->v_ = static_cast<enc_>(i); } template <unsigned n> @@ -196,7 +199,7 @@ static const int min = - max; mln_precondition(i >= min); mln_precondition(i <= max); - this->v_ = i; + this->v_ = static_cast<enc_>(i); return *this; } Index: mln/value/int_u.hh --- mln/value/int_u.hh (revision 3090) +++ mln/value/int_u.hh (working copy) @@ -183,7 +183,7 @@ { mln_precondition(i >= 0); mln_precondition(unsigned(i) <= mln_max(enc_)); - this->v_ = enc_(i); + this->v_ = static_cast<enc_>(i); } template <unsigned n> @@ -240,7 +240,7 @@ { mln_precondition(i >= 0); mln_precondition(unsigned(i) <= mln_max(enc_)); - this->v_ = i; + this->v_ = static_cast<enc_>(i); return *this; } Index: mln/value/float01.hh --- mln/value/float01.hh (revision 3090) +++ mln/value/float01.hh (working copy) @@ -1,5 +1,5 @@ -// Copyright (C) 2006, 2007, 2008 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2006, 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 @@ -167,16 +167,16 @@ inline float01::float01(unsigned nbits, float val) - : nbits_(nbits), - val_(unsigned(val * internal::two_pow_n_minus_1(nbits))) + : nbits_(nbits) { + val_ = static_cast<unsigned long>(val * float(internal::two_pow_n_minus_1(nbits))); } inline float float01::value() const { mln_invariant(nbits_ != 0); - return double(val_) / internal::two_pow_n_minus_1(nbits_); + return float(val_) / float(internal::two_pow_n_minus_1(nbits_)); } inline @@ -228,7 +228,7 @@ float01::operator float() const { mln_precondition(nbits_ != 0); - float tmp = float(val_) / internal::two_pow_n_minus_1(nbits_); + float tmp = float(val_) / float(internal::two_pow_n_minus_1(nbits_)); return tmp; } Index: mln/make/win_chamfer.hh --- mln/make/win_chamfer.hh (revision 3090) +++ mln/make/win_chamfer.hh (working copy) @@ -1,4 +1,5 @@ // Copyright (C) 2006, 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,18 +26,20 @@ // reasons why the executable file might be covered by the GNU General // Public License. - #ifndef MLN_MAKE_WIN_CHAMFER_HH -# define MLN_MAKE_WIN_CHAMFER_HH\ +# define MLN_MAKE_WIN_CHAMFER_HH /// \file mln/make/win_chamfer.hh /// /// Routine to create chamfer mln::w_window2d_int. +/// +/// \todo Revamp! +# include <cmath> # include <mln/core/alias/w_window2d_int.hh> # include <mln/core/alias/w_window2d_float.hh> -# include <math.h> + namespace mln { @@ -45,46 +48,40 @@ { template<int d10, int d11> - const mln::w_window2d_int mk_chamfer_3x3_int(); + mln::w_window2d_int + mk_chamfer_3x3_int(); template<int d10, int d11, int d21> - const mln::w_window2d_int mk_chamfer_5x5_int(); + mln::w_window2d_int + mk_chamfer_5x5_int(); - const mln::w_window2d_float mk_chamfer_3x3_float(float d10, float d11); + mln::w_window2d_float + mk_chamfer_3x3_float(float d10, float d11); - const mln::w_window2d_float + mln::w_window2d_float mk_chamfer_5x5_float(float d10, float d11, float d21); - const mln::w_window2d_float mk_chamfer_exact(); - - } // end of namespace mln::make - -} // end of namespace mln + mln::w_window2d_float + mk_chamfer_exact(); # ifndef MLN_INCLUDE_ONLY -namespace mln -{ - - namespace make - { - template<int d10, int d11> inline - const mln::w_window2d_int + mln::w_window2d_int mk_chamfer_3x3_int() { int ws[] = { d11, d10, d11, d10, 0, 0, 0, 0, 0 }; - return (make::w_window2d(ws)); + return make::w_window2d(ws); } template<int d10, int d11, int d21> inline - const mln::w_window2d_int + mln::w_window2d_int mk_chamfer_5x5_int() { int ws[] = { 0, d21, 0, d21, 0, @@ -93,22 +90,22 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - return (make::w_window2d(ws)); + return make::w_window2d(ws); } inline - const mln::w_window2d_float + mln::w_window2d_float mk_chamfer_3x3_float(float d10, float d11) { float ws[] = { d11, d10, d11, d10, 0, 0, 0, 0, 0 }; - return (make::w_window2d(ws)); + return make::w_window2d(ws); } inline - const mln::w_window2d_float + mln::w_window2d_float mk_chamfer_5x5_float(float d10, float d11, float d21) { float ws[] = { 0, d21, 0, d21, 0, @@ -117,25 +114,26 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - return (make::w_window2d(ws)); + return make::w_window2d(ws); } inline - const mln::w_window2d_float + mln::w_window2d_float mk_chamfer_exact() { - float r2 = sqrt(2); + float r2 = static_cast<float>(std::sqrt(2)); float ws[] = { r2, 1, r2, 1, 0, 0, 0, 0, 0 }; - return (make::w_window2d(ws)); + return make::w_window2d(ws); } +# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln::make } // end of namespace mln -# endif // !MLN_INCLUDE_ONLY #endif // ! MLN_MAKE_WIN_CHAMFER_HH Index: mln/make/image.hh --- mln/make/image.hh (revision 3090) +++ mln/make/image.hh (working copy) @@ -85,7 +85,8 @@ { mlc_bool(L != 0)::check(); mln::image1d<V> tmp(L); - for (unsigned ind = 0; ind < L; ++ind) + const def::coord ninds = static_cast<def::coord>(L); + for (def::coord ind = 0; ind < ninds; ++ind) tmp(point1d(ind)) = values[ind]; return tmp; } @@ -96,8 +97,11 @@ { mlc_bool(R != 0 && C != 0)::check(); mln::image2d<V> tmp(R, C); - for (unsigned row = 0; row < R; ++row) - for (unsigned col = 0; col < C; ++col) + const def::coord + nrows = static_cast<def::coord>(R), + ncols = static_cast<def::coord>(C); + for (def::coord row = 0; row < nrows; ++row) + for (def::coord col = 0; col < ncols; ++col) opt::at(tmp, row, col) = values[row][col]; return tmp; } @@ -108,9 +112,13 @@ { mlc_bool(S != 0 && R != 0 && C != 0)::check(); mln::image3d<V> tmp(S, R, C); - for (unsigned sli = 0; sli < S; ++sli) - for (unsigned row = 0; row < R; ++row) - for (unsigned col = 0; col < C; ++col) + const def::coord + nslis = static_cast<def::coord>(S), + nrows = static_cast<def::coord>(R), + ncols = static_cast<def::coord>(C); + for (def::coord sli = 0; sli < nslis; ++sli) + for (def::coord row = 0; row < nrows; ++row) + for (def::coord col = 0; col < ncols; ++col) opt::at(tmp, sli, row, col) = values[sli][row][col]; return tmp; } Index: mln/make/box2d_h.hh --- mln/make/box2d_h.hh (revision 3090) +++ mln/make/box2d_h.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_MAKE_BOX2D_H_HH # define MLN_MAKE_BOX2D_H_HH -/*! \file mln/make/box2d_h.hh - * - * \brief Routines to construct an mln::box2d_h. - */ +/// \file mln/make/box2d_h.hh +/// +/// Routines to construct an mln::box2d_h. # include <mln/core/alias/box2d_h.hh> # include <mln/make/point2d_h.hh> @@ -68,8 +68,8 @@ * * \return A 2D_H box. */ - mln::box2d_h box2d_h(int min_row, int min_col, - int max_row, int max_col); + mln::box2d_h box2d_h(def::coord min_row, def::coord min_col, + def::coord max_row, def::coord max_col); # ifndef MLN_INCLUDE_ONLY @@ -79,13 +79,14 @@ { mln_precondition(nrows != 0 && ncols != 0); mln::box2d_h tmp(point2d_h(0, 0), - point2d_h(nrows - 1, ncols - 1)); + point2d_h(static_cast<def::coord>(nrows - 1), + static_cast<def::coord>(ncols - 1))); return tmp; } inline - mln::box2d_h box2d_h(int min_row, int min_col, - int max_row, int max_col) + mln::box2d_h box2d_h(def::coord min_row, def::coord min_col, + def::coord max_row, def::coord max_col) { mln_precondition(max_row >= min_row && max_col >= min_col); mln::box2d_h tmp(point2d_h(min_row, min_col), Index: mln/make/point2d_h.hh --- mln/make/point2d_h.hh (revision 3090) +++ mln/make/point2d_h.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_MAKE_POINT2D_H_HH # define MLN_MAKE_POINT2D_H_HH -/*! \file mln/make/point2d_h.hh - * - * \brief Routine to construct an mln::point2d_h. - */ +/// \file mln/make/point2d_h.hh +/// +/// Routine to construct an mln::point2d_h. # include <mln/core/alias/point2d_h.hh> @@ -49,13 +49,13 @@ * * \return A 2D point. */ - mln::point2d_h point2d_h(int row, int col); + mln::point2d_h point2d_h(def::coord row, def::coord col); # ifndef MLN_INCLUDE_ONLY inline - mln::point2d_h point2d_h(int row, int col) + mln::point2d_h point2d_h(def::coord row, def::coord col) { mln::point2d_h tmp; tmp[0] = row; Index: mln/make/dpoint2d_h.hh --- mln/make/dpoint2d_h.hh (revision 3090) +++ mln/make/dpoint2d_h.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_MAKE_DPOINT2D_H_HH # define MLN_MAKE_DPOINT2D_H_HH -/*! \file mln/make/dpoint2d_h.hh - * - * \brief Routine to construct an mln::dpoint2d_h. - */ +/// \file mln/make/dpoint2d_h.hh +/// +/// Routine to construct an mln::dpoint2d_h. # include <mln/core/alias/dpoint2d_h.hh> @@ -49,13 +49,13 @@ * * \return A 2D dpoint. */ - mln::dpoint2d_h dpoint2d_h(int row, int col); + mln::dpoint2d_h dpoint2d_h(def::coord row, def::coord col); # ifndef MLN_INCLUDE_ONLY inline - mln::dpoint2d_h dpoint2d_h(int row, int col) + mln::dpoint2d_h dpoint2d_h(def::coord row, def::coord col) { mln::dpoint2d_h tmp; tmp[0] = row; Index: mln/make/box1d.hh --- mln/make/box1d.hh (revision 3090) +++ mln/make/box1d.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_MAKE_BOX1D_HH # define MLN_MAKE_BOX1D_HH -/*! \file mln/make/box1d.hh - * - * \brief Routines to construct an mln::box1d. - */ +/// \file mln/make/box1d.hh +/// +/// Routines to construct an mln::box1d. # include <mln/core/alias/box1d.hh> @@ -74,7 +74,7 @@ { mln_precondition(ninds != 0); mln::box1d tmp(point1d(0), - point1d(ninds - 1)); + point1d(static_cast<def::coord>(ninds - 1))); return tmp; } Index: mln/make/box2d.hh --- mln/make/box2d.hh (revision 3090) +++ mln/make/box2d.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_MAKE_BOX2D_HH # define MLN_MAKE_BOX2D_HH -/*! \file mln/make/box2d.hh - * - * \brief Routines to construct an mln::box2d. - */ +/// \file mln/make/box2d.hh +/// +/// Routines to construct an mln::box2d. # include <mln/core/alias/box2d.hh> Index: mln/make/box3d.hh --- mln/make/box3d.hh (revision 3090) +++ mln/make/box3d.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_MAKE_BOX3D_HH # define MLN_MAKE_BOX3D_HH -/*! \file mln/make/box3d.hh - * - * \brief Routines to construct an mln::box3d. - */ +/// \file mln/make/box3d.hh +/// +/// Routines to construct an mln::box3d. # include <mln/core/alias/box3d.hh> @@ -84,7 +84,9 @@ { mln_precondition(nrows != 0 && ncols != 0 && nslis != 0); mln::box3d tmp(point3d(0, 0, 0), - point3d(nslis - 1, nrows - 1, ncols - 1)); + point3d(static_cast<def::coord>(nslis - 1), + static_cast<def::coord>(nrows - 1), + static_cast<def::coord>(ncols - 1))); return tmp; } Index: mln/border/mirror.hh --- mln/border/mirror.hh (revision 3090) +++ mln/border/mirror.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,12 @@ #ifndef MLN_BORDER_MIRROR_HH # define MLN_BORDER_MIRROR_HH -/*! \file mln/border/mirror.hh - * - * \brief Define function that fills border using nearer pixels with a - * mirroring effect. - */ +/// \file mln/border/mirror.hh +/// +/// Define function that fills border using nearer pixels with a +/// mirroring effect. +/// +/// \todo Awful code: rewrite it! # include <mln/core/image/image1d.hh> # include <mln/core/image/image2d.hh> @@ -47,6 +49,7 @@ # include <mln/geom/max_col.hh> # include <mln/geom/ninds.hh> + namespace mln { Index: mln/convert/to_image.hh --- mln/convert/to_image.hh (revision 3090) +++ mln/convert/to_image.hh (working copy) @@ -47,6 +47,7 @@ # include <mln/core/image/image1d.hh> # include <mln/core/image/image2d.hh> # include <mln/core/image/image3d.hh> +# include <mln/convert/from_to.hh> namespace mln Index: mln/win/line.hh --- mln/win/line.hh (revision 3090) +++ mln/win/line.hh (working copy) @@ -111,8 +111,10 @@ mln_precondition(length % 2 == 1); dpoint<M,C> n; n.set_all(0); - const int dc = length / 2; - for (int c = - dc; c <= dc; ++c) + const def::coord + dc = static_cast<def::coord>(length / 2), + minus_dc = static_cast<def::coord>(- dc); + for (def::coord c = minus_dc; c <= dc; ++c) { n[i] = c; this->insert(n); Index: mln/win/diag2d.hh --- mln/win/diag2d.hh (revision 3090) +++ mln/win/diag2d.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_DIAG2D_HH # define MLN_WIN_DIAG2D_HH -/*! \file mln/win/diag2d.hh - * - * \brief Definition of the mln::win::diag2d window. - */ +/// \file mln/win/diag2d.hh +/// +/// Definition of the mln::win::diag2d window. # include <mln/core/internal/classical_window_base.hh> # include <mln/core/alias/dpoint2d.hh> @@ -93,9 +93,12 @@ : length_(length) { mln_precondition(length % 2 == 1); - const int dcol = length / 2; - for (int col = - dcol; col <= dcol; ++col) - insert(dpoint2d(-col, col)); + const def::coord + dcol = static_cast<def::coord>(length) / 2, + minus_dcol = static_cast<def::coord>(-dcol); + for (def::coord col = minus_dcol; col <= dcol; ++col) + insert(dpoint2d(static_cast<def::coord>(-col), + col)); } inline Index: mln/win/backdiag2d.hh --- mln/win/backdiag2d.hh (revision 3090) +++ mln/win/backdiag2d.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_BACKDIAG2D_HH # define MLN_WIN_BACKDIAG2D_HH -/*! \file mln/win/backdiag2d.hh - * - * \brief Definition of the mln::win::backdiag2d window. - */ +/// \file mln/win/backdiag2d.hh +/// +/// Definition of the mln::win::backdiag2d window. # include <mln/core/internal/classical_window_base.hh> # include <mln/core/alias/dpoint2d.hh> @@ -93,8 +93,10 @@ : length_(length) { mln_precondition(length % 2 == 1); - const int dcol = length / 2; - for (int col = - dcol; col <= dcol; ++col) + const def::coord + dcol = static_cast<def::coord>(length / 2), + minus_dcol = static_cast<def::coord>(- dcol); + for (def::coord col = minus_dcol; col <= dcol; ++col) insert(dpoint2d(col, col)); } Index: mln/win/octagon2d.hh --- mln/win/octagon2d.hh (revision 3090) +++ mln/win/octagon2d.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_OCTAGON2D_HH # define MLN_WIN_OCTAGON2D_HH -/*! \file mln/win/octagon2d.hh - * - * \brief Definition of the mln::win::octagon2d window. - */ +/// \file mln/win/octagon2d.hh +/// +/// Definition of the mln::win::octagon2d window. # include <mln/core/internal/classical_window_base.hh> # include <mln/core/alias/dpoint2d.hh> @@ -101,29 +101,42 @@ : length_(length) { mln_precondition(length % 6 == 1); - const int y = length / 6; - const int x = y * 2; - const int z = y + x; + const def::coord + y = static_cast<def::coord>(length / 6), + x = static_cast<def::coord>(y * 2), + z = static_cast<def::coord>(y + x); insert(dpoint2d(0, 0)); - for (int a = 1; a <= x; ++a) - for (int b = 0; b <= x; ++b) + for (def::coord a = 1; a <= x; ++a) + for (def::coord b = 0; b <= x; ++b) { + def::coord + _a = static_cast<def::coord>(-a), + _b = static_cast<def::coord>(-b); insert(dpoint2d(a, b)); - insert(dpoint2d(-b, a)); - insert(dpoint2d(b, -a)); - insert(dpoint2d(-a, -b)); - } - for (int a = x + 1; a <= z; ++a) - for (int b = -2 * x + a; b <= 2 * x - a; ++b) - { + insert(dpoint2d(_b, a)); + insert(dpoint2d(b, _a)); + insert(dpoint2d(_a, _b)); + } + const def::coord a_min = static_cast<def::coord>(x + 1); + for (def::coord a = a_min; a <= z; ++a) + { + const def::coord + b_min = static_cast<def::coord>(-2 * x + a), + b_max = static_cast<def::coord>(2 * x - a); + for (def::coord b = b_min; b <= b_max; ++b) + { + def::coord + _a = static_cast<def::coord>(-a), + _b = static_cast<def::coord>(-b); insert(dpoint2d(a, b)); - insert(dpoint2d(a, -b)); - insert(dpoint2d(-a, b)); - insert(dpoint2d(-a, -b)); + insert(dpoint2d(a, _b)); + insert(dpoint2d(_a, b)); + insert(dpoint2d(_a, _b)); insert(dpoint2d(b, a)); - insert(dpoint2d(b, -a)); - insert(dpoint2d(-b, a)); - insert(dpoint2d(-b, -a)); + insert(dpoint2d(b, _a)); + insert(dpoint2d(_b, a)); + insert(dpoint2d(_b, _a)); + } } } Index: mln/win/disk2d.hh --- mln/win/disk2d.hh (revision 3090) +++ mln/win/disk2d.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_DISK2D_HH # define MLN_WIN_DISK2D_HH -/*! \file mln/win/disk2d.hh - * - * \brief Definition of the mln::win::disk2d window. - */ +/// \file mln/win/disk2d.hh +/// +/// Definition of the mln::win::disk2d window. # include <mln/core/internal/classical_window_base.hh> # include <mln/core/alias/dpoint2d.hh> @@ -48,7 +48,7 @@ /*! \brief Disk window defined on the 2D square grid. * - * An disk2d is centered and symmetric. + * A disk2d is centered and symmetric. * */ struct disk2d : public internal::classical_window_base< dpoint2d, disk2d > @@ -84,10 +84,12 @@ : length_(length) { mln_precondition(length % 2 == 1); - const int r = length / 2; - const int r2 = r * r; - for (int a = -r; a <= r; ++a) - for (int b = -r; b <= r; ++b) + const def::coord + r = static_cast<def::coord>(length / 2), + minus_r = static_cast<def::coord>(-r), + r2 = static_cast<def::coord>(r * r); + for (def::coord a = minus_r; a <= r; ++a) + for (def::coord b = minus_r; b <= r; ++b) if (a * a + b * b <= r2) insert(dpoint2d(a, b)); } Index: mln/algebra/mat.hh --- mln/algebra/mat.hh (revision 3090) +++ mln/algebra/mat.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2006 EPITA Research and Development Laboratory +// Copyright (C) 2006, 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_ALGEBRA_MAT_HH # define MLN_ALGEBRA_MAT_HH -/*! - * \file mln/algebra/mat.hh - * - * \brief Definition of a generic matrix class. - */ +/// \file mln/algebra/mat.hh +/// +/// Definition of a generic matrix class. # include <iostream> @@ -309,7 +308,7 @@ { for (unsigned i = 0; i < n; ++i) for (unsigned j = 0; j < m; ++j) - data_[i][j] = rhs(i, j); + data_[i][j] = static_cast<T>( rhs(i, j) ); } template <unsigned n, unsigned m, typename T> @@ -321,7 +320,7 @@ const F& f = exact(f_); for (unsigned i = 0; i < n; ++i) for (unsigned j = 0; j < m; ++j) - data_[i][j] = f(i * n + j); + data_[i][j] = static_cast<T>( f(i * n + j) ); } template <unsigned n, unsigned m, typename T> @@ -332,7 +331,7 @@ { for (unsigned i = 0; i < n; ++i) for (unsigned j = 0; j < m; ++j) - data_[i][j] = rhs(i, j); + data_[i][j] = static_cast<T>( rhs(i, j) ); return *this; } Index: mln/algebra/h_vec.hh --- mln/algebra/h_vec.hh (revision 3090) +++ mln/algebra/h_vec.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_ALGEBRA_H_VEC_HH # define MLN_ALGEBRA_H_VEC_HH -/*! \file mln/algebra/h_vec.hh - * - * \brief Definition of a vector with homogeneous coordinates. - */ +/// \file mln/algebra/h_vec.hh +/// +/// Definition of a vector with homogeneous coordinates. # include <mln/algebra/vec.hh> # include <mln/literal/one.hh> @@ -150,7 +150,7 @@ vec<d,C> tmp; for (unsigned i = 0; i < d; ++i) - tmp[i] = this->data_[i] / w; + tmp[i] = static_cast<C>(this->data_[i] / w); return tmp; } Index: mln/algebra/vec.hh --- mln/algebra/vec.hh (revision 3090) +++ mln/algebra/vec.hh (working copy) @@ -383,7 +383,7 @@ : super_() { for (unsigned i = 0; i < n; ++i) - data_[i] = rhs[i]; + data_[i] = static_cast<T>(rhs[i]); } template <unsigned n, typename T> @@ -392,7 +392,7 @@ vec<n,T>& vec<n,T>::operator=(const vec<n, U>& rhs) { for (unsigned i = 0; i < n; ++i) - data_[i] = rhs[i]; + data_[i] = static_cast<T>(rhs[i]); return *this; } @@ -436,7 +436,7 @@ n_l2 += data_[i] * data_[i]; n_l2 = sqrt(n_l2); for (unsigned i = 0; i < n; ++i) - data_[i] = T(data_[i] / n_l2); + data_[i] = static_cast<T>(data_[i] / n_l2); return *this; } @@ -448,7 +448,7 @@ mlc_converts_to(mln_result(F), T)::check(); const F& f = exact(f_); for (unsigned i = 0; i < n; ++i) - data_[i] = f(i); + data_[i] = static_cast<T>(f(i)); } @@ -478,7 +478,8 @@ vec<n, mln_trait_op_plus(T,U)> operator+(const vec<n,T>& lhs, const vec<n,U>& rhs) { - vec<n, mln_trait_op_plus(T,U)> tmp; + typedef mln_trait_op_plus(T,U) R; + vec<n, R> tmp; for (unsigned i = 0; i < n; ++i) tmp[i] = lhs[i] + rhs[i]; return tmp; @@ -489,7 +490,8 @@ vec<n, mln_trait_op_minus(T,U)> operator-(const vec<n,T>& lhs, const vec<n,U>& rhs) { - vec<n, mln_trait_op_minus(T,U)> tmp; + typedef mln_trait_op_minus(T,U) R; + vec<n, R> tmp; for (unsigned i = 0; i < n; ++i) tmp[i] = lhs[i] - rhs[i]; return tmp; @@ -500,6 +502,7 @@ mln_sum_x(T,U) operator*(const vec<n,T>& lhs, const vec<n,U>& rhs) { + typedef mln_sum_x(T,U) R; mln_sum_x(T,U) tmp(literal::zero); for (unsigned i = 0; i < n; ++i) tmp += lhs[i] * rhs[i]; @@ -521,7 +524,8 @@ // If we really want to propage the "scalar" status then // we shall allow for scalar(scalar(..)) !!! => FIXME - vec<n, mln_trait_op_times(T, S)> tmp; + typedef mln_trait_op_times(T, S) R; + vec<n, R> tmp; for (unsigned i = 0; i < n; ++i) tmp[i] = lhs[i] * s.to_equiv(); return tmp; @@ -533,7 +537,8 @@ operator/(const vec<n,T>& lhs, const mln::value::scalar_<S>& s) { mln_precondition(value::equiv(s) != (S)(literal::zero)); - vec<n, mln_trait_op_div(T, S)> tmp; + typedef mln_trait_op_div(T, S) R; + vec<n, R> tmp; for (unsigned i = 0; i < n; ++i) tmp[i] = lhs[i] / s.to_equiv(); return tmp; Index: mln/io/pnm/save_header.hh --- mln/io/pnm/save_header.hh (revision 3090) +++ mln/io/pnm/save_header.hh (working copy) @@ -1,5 +1,5 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA -// Research and Development Laboratory +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 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 @@ -29,12 +29,9 @@ #ifndef MLN_IO_PNM_SAVE_HEADER_HH # define MLN_IO_PNM_SAVE_HEADER_HH -/*! - * \file mln/io/pnm/save_header.hh - * - * \brief Define a function which saves header for PNM image. - * - */ +/// \file mln/io/pnm/save_header.hh +/// +/// Define a function which saves header for PNM image. # include <iostream> # include <fstream> @@ -45,6 +42,7 @@ # include <mln/geom/nrows.hh> # include <mln/geom/ncols.hh> + namespace mln { @@ -70,7 +68,7 @@ template <typename I> inline - void save_header(const char type, + void save_header(char type, const I& ima, const std::string& filename, std::ofstream& file) { Index: mln/io/pnm/load_header.hh --- mln/io/pnm/load_header.hh (revision 3090) +++ mln/io/pnm/load_header.hh (working copy) @@ -60,7 +60,7 @@ // check magic if (istr.get() != 'P' ) goto err; - type = istr.get(); + type = static_cast<char>(istr.get()); if (type < '1' || type > '6') goto err; Index: mln/io/pnm/save.hh --- mln/io/pnm/save.hh (revision 3090) +++ mln/io/pnm/save.hh (working copy) @@ -1,5 +1,5 @@ // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 EPITA -// Research and Development Laboratory +// 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,13 +29,10 @@ #ifndef MLN_IO_PNM_SAVE_HH # define MLN_IO_PNM_SAVE_HH -/*! - * \file mln/io/pnm/save.hh - * - * \brief Define a function which saves an image of kind PNM into - * given path. - * - */ +/// \file mln/io/pnm/save.hh +/// +/// Define a function which saves an image of kind PNM into +/// given path. # include <iostream> # include <fstream> @@ -72,7 +69,8 @@ * \param[in,out] filename the destination. */ template <typename I> - void save(const int type, const Image<I>& ima_, const std::string& filename); + void save(char type, const Image<I>& ima_, const std::string& filename); + # ifndef MLN_INCLUDE_ONLY @@ -116,7 +114,7 @@ void save_data_uncontiguous(std::ofstream& file, const I& ima) { - const int + const def::coord min_row = geom::min_row(ima), max_row = geom::max_row(ima), min_col = geom::min_col(ima), @@ -136,7 +134,7 @@ const I& ima_) { const I& ima = exact(ima_); - const int + const def::coord min_row = geom::min_row(ima), max_row = geom::max_row(ima); point2d p; @@ -175,7 +173,7 @@ template <typename I> inline - void save(const int type, const Image<I>& ima_, const std::string& filename) + void save(char type, const Image<I>& ima_, const std::string& filename) { trace::entering("mln::io::pnm::save"); const I& ima = exact(ima_); Index: mln/io/pnm/load.hh --- mln/io/pnm/load.hh (revision 3090) +++ mln/io/pnm/load.hh (working copy) @@ -29,12 +29,10 @@ #ifndef MLN_IO_PNM_LOAD_HH # define MLN_IO_PNM_LOAD_HH -/*! - * \file mln/io/pnm/load.hh - * - * \brief Define a function which loads an image of kind PNM 8/16bits with - * given path. - */ +/// \file mln/io/pnm/load.hh +/// +/// Define a function which loads an image of kind PNM 8/16bits with +/// given path. # include <iostream> # include <fstream> @@ -104,7 +102,7 @@ inline void load_raw_2d_uncontiguous(std::ifstream& file, image2d<V>& ima) { - const int + const def::coord min_row = geom::min_row(ima), max_row = geom::max_row(ima), min_col = geom::min_col(ima), @@ -171,7 +169,7 @@ char type = 0; int nrows, ncols; unsigned int maxval; - read_header(type_ - 3, type_, file, type, + read_header(static_cast<char>(type_ - 3), type_, file, type, nrows, ncols, maxval); if (max_component(V()) != maxval) @@ -223,7 +221,7 @@ char type = 0; int nrows, ncols; unsigned int maxval; - read_header(type_ - 3, type_, file, type, + read_header(static_cast<char>(type_ - 3), type_, file, type, nrows, ncols, maxval); if (max_component(mln_value(I)()) != maxval) Index: mln/io/pbm/save.hh --- mln/io/pbm/save.hh (revision 3090) +++ mln/io/pbm/save.hh (working copy) @@ -1,5 +1,5 @@ // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 EPITA -// Research and Development Laboratory +// 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,13 +29,10 @@ #ifndef MLN_IO_PBM_SAVE_HH # define MLN_IO_PBM_SAVE_HH -/*! - * \file mln/io/pbm/save.hh - * - * \brief Define a function which saves an image of kind pbm into - * given path. - * - */ +/// \file mln/io/pbm/save.hh +/// +/// Define a function which saves an image of kind pbm into +/// given path. # include <iostream> # include <fstream> @@ -86,27 +83,31 @@ io::pnm::save_header(PBM, ima, filename, file); - int ncols = geom::ncols(ima); - int col = 0; - int stride = 0; + def::coord + ncols = static_cast<def::coord>(geom::ncols(ima)), + col = 0, + stride = 0; unsigned char c = 0; mln_fwd_piter(I) p(ima.domain()); for_all(p) { - c <<= 1; - c += (ima(p) == true ? 0 : 1); // In pbm, '0' means 'white' so 'object', thus 'true'! + c = static_cast<unsigned char>(c << 1); + if (ima(p) == false) + ++c; // In pbm, '0' means 'white' so 'object', thus 'true'! if (++col >= ncols) { - c <<= (8 - stride - 1); + c = static_cast<unsigned char>(c << (8 - stride - 1)); file << c; - c = col = stride = 0; + c = 0; + col = stride = 0; } else if (++stride >= 8) { file << c; - c = stride = 0; + c = 0; + stride = 0; } } mln_postcondition(stride == 0); Index: tests/data/fill.cc --- tests/data/fill.cc (revision 3090) +++ tests/data/fill.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,30 +26,25 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/data/fill.cc - * - * \brief Tests on mln::data::fill - */ +/// \file tests/data/fill.cc +/// +/// Tests on mln::data::fill #include <mln/core/image/image2d.hh> #include <mln/data/fill.hh> + int main() { using namespace mln; - unsigned u = 300; - unsigned char uc = u; - mln_assertion(uc == 44); - - { const unsigned size = 3; image2d<unsigned> ima(size, size); + + unsigned u = 300; data::fill(ima, u); box_fwd_piter_<point2d> p(ima.domain()); for_all (p) mln_assertion (ima(p) == u); } - -} Index: tests/border/fill_full.cc --- tests/border/fill_full.cc (revision 3090) +++ tests/border/fill_full.cc (working copy) @@ -258,8 +258,8 @@ { typedef value::float01_8 T; - T value = T(0.9999); - T v = T(0.111); + T value = static_cast<T>(0.9999f); + T v = static_cast<T>(0.111f); for (int i = 1; i < limits; ++i) for (int j = 1; j < limits; ++j) @@ -273,8 +273,8 @@ { typedef value::float01_16 T; - T value = T(0.9999); - T v = T(0.111); + T value = static_cast<T>(0.9999f); + T v = static_cast<T>(0.111f); for (int i = 1; i < limits; ++i) for (int j = 1; j < limits; ++j) Index: tests/convert/to_p_array.cc --- tests/convert/to_p_array.cc (revision 3090) +++ tests/convert/to_p_array.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 @@ -38,6 +39,7 @@ #include <mln/convert/to_p_array.hh> + int main() { using namespace mln; @@ -48,7 +50,7 @@ vec1d v1(convert::to_p_array(win1d, p1)); { - unsigned col = 4; + def::coord col = 4; for (size_t i=0; i < v1.nsites(); i++) mln_assertion(v1[i] == point1d(col++)); } @@ -58,11 +60,11 @@ win::rectangle2d win2d(3, 3); vec2d v2(convert::to_p_array(win2d, p2)); - unsigned row = 9; + def::coord row = 9; for (unsigned col = 0; col < v2.nsites(); ++col) { if (col > 0 && !(col%3)) ++row; - mln_assertion(v2[col] == point2d(row, 9 + (col%3))); + mln_assertion(v2[col] == point2d(row, static_cast<def::coord>(9 + (col%3)))); } } Index: tests/convert/to_image.cc --- tests/convert/to_image.cc (revision 3090) +++ tests/convert/to_image.cc (working copy) @@ -27,6 +27,7 @@ // Public License. /// \file tests/convert/to_image.cc +/// /// Tests on mln::convert::to_image. #include <mln/core/image/image2d.hh> Index: tests/win/diag2d.cc --- tests/win/diag2d.cc (revision 3090) +++ tests/win/diag2d.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,19 +26,17 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/win/diag2d.cc - * - * \brief Tests on mln::win::diag2d. - */ +/// \file tests/win/diag2d.cc +/// +/// Tests on mln::win::diag2d. #include <cmath> #include <mln/win/diag2d.hh> - #include <mln/convert/to_image.hh> - #include <mln/debug/println.hh> + int main() { using namespace mln; @@ -47,8 +46,8 @@ mln_assertion(diag.delta() == 2); - for (int x = -5; x <= 5; ++x) - for (int y = -5; y <= 5; ++y) + for (def::coord x = -5; x <= 5; ++x) + for (def::coord y = -5; y <= 5; ++y) { mln_assertion(((abs(x) <= 2) && (abs(y) <= 2)) || !diag.has(dpoint2d(x, y)));
participants (1)
-
Thierry Geraud