
* mln/convert/from_to.hxx: Add new prototypes. * mln/core/point.hh: Add new from_to overloads. Remove specialized constructors causing ambiguities. --- milena/ChangeLog | 9 ++ milena/doc/figures/fill-subdomain-2.ppm | Bin 206 -> 206 bytes milena/mln/convert/from_to.hxx | 10 ++ milena/mln/core/point.hh | 162 ++++++++++++++++++++++--------- 4 files changed, 133 insertions(+), 48 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 0ba1a95..e265636 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,12 @@ +2010-07-01 Guillaume Lazzara <z@lrde.epita.fr> + + Add from_to overloads for conversions from algebra::vec to point. + + * mln/convert/from_to.hxx: Add new prototypes. + + * mln/core/point.hh: Add new from_to overloads. Remove specialized + constructors causing ambiguities. + 2010-06-03 Guillaume Lazzara <z@lrde.epita.fr> Add a function to convert qt::rgb32 values to int_u8. diff --git a/milena/doc/figures/fill-subdomain-2.ppm b/milena/doc/figures/fill-subdomain-2.ppm index 31ae37215fdfc5fe715aef7117f676ee6066ab0f..0e507e87c48d7fd2f555801024e916fe6fc13d5c 100644 GIT binary patch delta 94 wcmX@dc#d&GdH9_>xj@7K187{BFo>R=C=WzH#+`st2p7Tza)AgU1r&h*0MhUlfdBvi delta 94 wcmX@dc#d&Gd3Z;!CJ-^e02&u245BwgPXZz!W3}FM2p7Tza)AgU1r&h*00lu6X#fBK diff --git a/milena/mln/convert/from_to.hxx b/milena/mln/convert/from_to.hxx index 5007baf..98f9420 100644 --- a/milena/mln/convert/from_to.hxx +++ b/milena/mln/convert/from_to.hxx @@ -147,6 +147,16 @@ namespace mln void from_to_(const point<G,C1>& from, point<G,C2>& to); + // algebra::vec -> point + template <unsigned n, typename C1, typename G, typename C2> + void + from_to_(const algebra::vec<n,C1>& from, point<G,C2>& to); + + // algebra::vec -> point + template <unsigned n, typename C1, typename G> + void + from_to_(const algebra::vec<n,C1>& from, point<G,C1>& to); + // algebra::vec -> Gpoint. template <unsigned n, typename T, typename P> void diff --git a/milena/mln/core/point.hh b/milena/mln/core/point.hh index 8da15b6..49a519e 100644 --- a/milena/mln/core/point.hh +++ b/milena/mln/core/point.hh @@ -74,6 +74,14 @@ namespace mln template <typename G, typename C1, typename C2> void from_to_(const point<G,C1>& from, point<G,C2>& to); + template <unsigned n, typename C1, typename G, typename C2> + void + from_to_(const algebra::vec<n,C1>& from, point<G,C2>& to); + + template <unsigned n, typename C1, typename G> + void + from_to_(const algebra::vec<n,C1>& from, point<G,C1>& to); + } // end of namespace mln::convert::over_load } // end of namespace mln::convert @@ -89,6 +97,7 @@ namespace mln { typedef algebra::vec<G::dim, float> ret; }; + } /// Generic point class. @@ -153,8 +162,6 @@ namespace mln point(const algebra::vec<dim,C2>& v); point(const algebra::vec<dim,C>& v); - point(const algebra::vec<dim,double>& v); - point(const algebra::vec<dim,float>& v); /// \{ Constructors with different numbers of arguments @@ -210,6 +217,9 @@ namespace mln /// Point with all coordinates set to the mininum value. static const point<G,C>& minus_infty(); + /// Return the underlying vector storing the coordinates. + algebra::vec<G::dim, C>& hook_coord_(); + protected: algebra::vec<G::dim, C> coord_; }; @@ -249,6 +259,49 @@ namespace mln # ifndef MLN_INCLUDE_ONLY + + namespace internal + { + + template <typename C, typename C2> + inline + C + convert_data_(metal::bool_<false>, const C2& v) + { + return static_cast<C>(v); + } + + template <typename C, typename C2> + inline + C + convert_data_(metal::bool_<true>, const C2& v) + { + return round(v); + } + + template <typename C, typename C2> + inline + C + convert_data(const C2& v) + { + // If (C != float && C != double) && (C2 == float || C2 == double) + // => We want to round the value. + // Otherwise we can just statically cast. + // + return convert_data_<C>( + typename mlc_and( + mlc_and(mlc_is_not(C,float), + mlc_is_not(C,double)), + mlc_or(mlc_is(C2,float), + mlc_is(C2, double)))::check_t(), v); + } + + + + } // end of namespace mln::internal + + + namespace convert { @@ -261,9 +314,57 @@ namespace mln from_to_(const point<G,C1>& from, point<G,C2>& to) { mlc_converts_to(C1,C2)::check(); - to = point<G,C2>(from.to_vec()); + enum { dim = G::dim }; + + for (unsigned i = 0; i < dim; ++i) + to[i] = internal::convert_data<C2>(from[i]); } + + template <unsigned n, typename C1, typename G, typename C2> + inline + void + from_to_(const algebra::vec<n,C1>& from, point<G,C2>& to) + { + mlc_converts_to(C1, C2)::check(); + enum { dim = G::dim }; + mlc_bool(G::dim == n)::check(); + + unsigned j = 0; + //FIXME: to be improved while adding a conversion routine. + if (dim < 3) + to.hook_coord_() = from; + else + { + for (unsigned i = dim - 2; i < dim; ++i) + to[i] = internal::convert_data<C2>(from[j++]); + for (unsigned i = 2; i < dim; ++i, ++j) + to[i-j] = internal::convert_data<C2>(from[j]); + } + } + + template <unsigned n, typename C1, typename G> + inline + void + from_to_(const algebra::vec<n,C1>& from, point<G,C1>& to) + { + enum { dim = G::dim }; + mlc_bool(G::dim == n)::check(); + + unsigned j = 0; + //FIXME: to be improved while adding a conversion routine. + if (dim < 3) + to.hook_coord_() = from; + else + { + for (unsigned i = dim - 2; i < dim; ++i) + to[i] = from[j++]; + for (unsigned i = 2; i < dim; ++i, ++j) + to[i-j] = from[j]; + } + } + + } // end of namespace mln::convert::over_load } // end of namespace mln::convert @@ -315,18 +416,7 @@ namespace mln inline point<G,C>::point(const algebra::vec<dim,C2>& v) { - mlc_converts_to(C2, C)::check(); - unsigned j = 0; - //FIXME: to be improved while adding a conversion routine. - if (dim < 3) - coord_ = v; - else - { - for (unsigned i = dim - 2; i < dim; ++i) - coord_[i] = static_cast<C>(v[j++]); - for (unsigned i = 2; i < dim; ++i, ++j) - coord_[i-j] = static_cast<C>(v[j]); - } + convert::over_load::from_to_(v, *this); } @@ -334,42 +424,10 @@ namespace mln inline point<G,C>::point(const algebra::vec<dim,C>& v) { - unsigned j = 0; - //FIXME: to be improved while adding a conversion routine. - if (dim < 3) - coord_ = v; - else - { - for (unsigned i = dim - 2; i < dim; ++i) - coord_[i] = v[j++]; - for (unsigned i = 2; i < dim; ++i, ++j) - coord_[i-j] = v[j]; - } + convert::over_load::from_to_(v, *this); } - template <typename G, typename C> - inline - point<G,C>::point(const algebra::vec<dim,double>& v) - { - unsigned j = 0; - for (unsigned i = dim - 2; i < dim; ++i) - coord_[i] = round(v[j++]); - for (unsigned i = 2; i < dim; ++i, ++j) - coord_[i-j] = round(v[j]); - } - - template <typename G, typename C> - inline - point<G,C>::point(const algebra::vec<dim,float>& v) - { - unsigned j = 0; - for (unsigned i = dim - 2; i < dim; ++i) - coord_[i] = round(v[j++]); - for (unsigned i = 2; i < dim; ++i, ++j) - coord_[i-j] = round(v[j]); - } - template <typename G, typename C> inline @@ -563,6 +621,14 @@ namespace mln return the_; } + template <typename G, typename C> + inline + algebra::vec<G::dim, C>& + point<G,C>::hook_coord_() + { + return coord_; + } + namespace internal { -- 1.5.6.5