Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 2009, 2010, 2011 EPITA Research and Development 00002 // Laboratory (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 00026 00027 #ifndef MLN_CONVERT_FROM_TO_HXX 00028 # define MLN_CONVERT_FROM_TO_HXX 00029 00031 00032 // All overloaded "convert::from_to" routines have to be declared in 00033 // the present file. It allows for *deferred* use of these routines. 00034 00035 # include <mln/core/def/all.hh> 00036 # include <mln/core/grids.hh> 00037 # include <mln/util/couple.hh> 00038 00039 //FIXME: have a forward declaration. 00040 # include <vector> 00041 # include <set> 00042 00043 00044 namespace mln 00045 { 00046 00047 00048 // Forward declarations. 00049 00050 template <typename E> struct Accumulator; 00051 template <typename E> struct Gdpoint; 00052 template <typename E> struct Gpoint; 00053 template <typename E> struct Image; 00054 template <typename E> struct Object; 00055 template <typename E> struct Proxy; 00056 template <typename E> struct Site_Set; 00057 template <typename E> struct Value; 00058 template <typename E> struct Weighted_Window; 00059 template <typename E> struct Window; 00060 00061 template <typename G, typename C> struct dpoint; 00062 template <typename G, typename C> struct point; 00063 00064 template <typename D> class neighb; 00065 template <typename D> class window; 00066 template <typename D, typename W> struct w_window; 00067 00068 template <typename T> struct image1d; 00069 00070 namespace algebra { 00071 template <unsigned n, typename T> class vec; 00072 template <unsigned d, typename C> class h_vec; 00073 } 00074 00075 namespace fun { 00076 namespace i2v { 00077 template <typename T> class array; 00078 } 00079 } 00080 00081 namespace histo { 00082 template <typename T> struct array; 00083 } 00084 00085 namespace util { 00086 template <typename T> class array; 00087 template <typename Tag, typename V> class object_id; 00088 } 00089 00090 namespace value { 00091 namespace qt { struct rgb32; } 00092 template <unsigned n> struct rgb; 00093 template <typename H, typename S, typename L> class hsl_; 00094 template <unsigned n> struct int_u; 00095 template <unsigned n> struct label; 00096 } 00097 00098 // end of Forward declarations. 00099 00100 00101 00102 // convert::to 00103 00104 namespace convert 00105 { 00106 00107 template <typename T, typename O> 00108 T 00109 to(const O& from); 00110 00111 } // end of namespace mln::convert 00112 00113 00114 00115 // convert::from_to 00116 00117 namespace convert 00118 { 00119 00120 // Facade 00121 00122 template <typename F, typename T> 00123 void 00124 from_to(const F& from, T& to); 00125 00126 00127 namespace over_load 00128 { 00129 00130 // Guard. 00131 template <typename F, typename T> 00132 void 00133 from_to_(const Object<F>&, Object<T>&); 00134 // end of Guard. 00135 00136 // Object -> Object 00137 template <typename T> 00138 void 00139 from_to_(const Object<T>& from, Object<T>& to); 00140 00141 // Object -> Object 00142 template <typename T> 00143 void 00144 from_to_(const T& from, T& to); 00145 00146 // point -> point. 00147 template <typename G, typename C1, typename C2> 00148 inline 00149 void 00150 from_to_(const point<G,C1>& from, point<G,C2>& to); 00151 00152 // algebra::vec -> point 00153 template <unsigned n, typename C1, typename G, typename C2> 00154 void 00155 from_to_(const algebra::vec<n,C1>& from, point<G,C2>& to); 00156 00157 // algebra::vec -> point 00158 template <unsigned n, typename C1, typename G> 00159 void 00160 from_to_(const algebra::vec<n,C1>& from, point<G,C1>& to); 00161 00162 // algebra::vec -> Gpoint. 00163 template <unsigned n, typename T, typename P> 00164 void 00165 from_to_(const algebra::vec<n,T>& from, Gpoint<P>& to_); 00166 00167 // algebra::vec -> rgb. 00168 template <typename T, unsigned m> 00169 void 00170 from_to_(const algebra::vec<3,T>& from, value::rgb<m>& to); 00171 00172 00173 // bool -> rgb. 00174 template <unsigned m> 00175 void 00176 from_to_(bool from, value::rgb<m>& to); 00177 00178 // rgb32 -> bool 00179 void 00180 from_to_(const value::qt::rgb32& from, bool& to); 00181 00182 // bool -> rgb32 00183 void 00184 from_to_(const bool& from, value::qt::rgb32& to); 00185 00186 // int_u -> rgb. 00187 template <unsigned m> 00188 void from_to_(const value::int_u<m>& from, value::rgb<m>& to); 00189 00190 // int_u -> qt::rgb32. 00191 template <unsigned m> 00192 void from_to_(const value::int_u<m>& from, value::qt::rgb32& to); 00193 00194 // int_u -> label 00195 template <unsigned n> 00196 void from_to_(const value::int_u<n>& from, value::label<n>& to_); 00197 00198 // int_u -> unsigned 00199 template <unsigned n> 00200 void from_to_(const value::int_u<n>& from, unsigned& to_); 00201 00202 // int_u -> bool. 00203 template <unsigned n> 00204 void 00205 from_to_(const value::int_u<n>& from, bool& to_); 00206 00207 // int_u -> float 00208 template <unsigned n> 00209 void from_to_(const value::int_u<n>& from, float& to_); 00210 00211 // int_u -> double 00212 template <unsigned n> 00213 void from_to_(const value::int_u<n>& from, double& to_); 00214 00215 // label -> int_u. 00216 template <unsigned n> 00217 void 00218 from_to_(const value::label<n>& from, value::int_u<n>& to_); 00219 00220 // label -> bool 00221 template <unsigned n> 00222 void from_to_(const value::label<n>& from, bool& to_); 00223 00224 // int_u<n> -> label<m> with n < m 00225 template <unsigned n, unsigned m> 00226 void 00227 from_to_(const value::int_u<n>& from, value::label<m>& to_); 00228 00229 // hsl -> rgb8. 00230 template <typename H, typename S, typename L> 00231 void from_to_(const value::hsl_<H,S,L>&, value::rgb<8>& to); 00232 00233 // hsl -> rgb16. 00234 template <typename H, typename S, typename L> 00235 void from_to_(const value::hsl_<H,S,L>&, value::rgb<16>& to); 00236 00237 // hsl -> qt::rgb32. 00238 template <typename H, typename S, typename L> 00239 void from_to_(const value::hsl_<H,S,L>&, value::qt::rgb32& to); 00240 00241 // rgb to hsl 00242 void 00243 from_to_(const value::rgb<16>& from, value::hsl_<float,float,float>& to); 00244 00245 // rgb to hsl 00246 void 00247 from_to_(const value::rgb<8>& from, value::hsl_<float,float,float>& to); 00248 00249 // rgb -> bool. 00250 template <unsigned m> 00251 void from_to_(const value::rgb<m>& from, bool& to); 00252 00253 00254 // C-array -> Image. 00255 template <typename V, unsigned S, typename I> 00256 void 00257 from_to_(const V (&values)[S], Image<I>& to); 00258 00259 // C-array -> w_window 00260 template <typename V, unsigned S, typename D, typename W> 00261 void 00262 from_to_(const V (&weight)[S], w_window<D,W>& to); 00263 00264 00265 // C-array -> window2d 00266 template <unsigned S> 00267 void 00268 from_to_(const bool (&values)[S], 00269 window< dpoint<grid::square, def::coord> >& win); 00270 00271 template <unsigned R, unsigned C> 00272 void 00273 from_to_(const bool (&values)[R][C], 00274 window< dpoint<grid::square, def::coord> >& win); 00275 00276 00277 // C-array -> window3d 00278 template <unsigned S> 00279 void 00280 from_to_(const bool (&values)[S], 00281 window< dpoint<grid::cube, def::coord> >& win); 00282 00283 00284 // C-array -> neighb2d 00285 template <unsigned S> 00286 void 00287 from_to_(const bool (&values)[S], 00288 neighb< window< dpoint<grid::square, def::coord> > >& nbh); 00289 00290 template <unsigned R, unsigned C> 00291 void 00292 from_to_(bool const (&values)[R][C], 00293 neighb< window< dpoint<grid::square, def::coord> > >& nbh); 00294 00295 00296 // C-array -> neighb3d 00297 template <unsigned S> 00298 void 00299 from_to_(const bool (&values)[S], 00300 neighb< window< dpoint<grid::cube, def::coord> > >& nbh); 00301 00302 00303 00304 // Gdpoint -> point 00305 template <typename D> 00306 void 00307 from_to_(const Gdpoint<D>& from, mln_site(D)& to); 00308 00309 00310 // Value -> Value 00311 template <typename F, typename T> 00312 void 00313 from_to_(const Value<F>& from, Value<T>& to); 00314 00315 // double-> Value 00316 template <typename V> 00317 void 00318 from_to_(const double& from, Value<V>& to); 00319 00320 // double-> unsigned 00321 void 00322 from_to_(const double& from, unsigned& to); 00323 00324 // double-> int 00325 void 00326 from_to_(const double& from, int& to); 00327 00328 // float -> Value 00329 template <typename V> 00330 void 00331 from_to_(const float& from, Value<V>& to); 00332 00333 // float -> unsigned 00334 void 00335 from_to_(const float& from, unsigned& to); 00336 00337 // float -> int 00338 void 00339 from_to_(const float& from, int& to); 00340 00341 // int -> Value 00342 template <typename T> 00343 void 00344 from_to_(const int& from, Value<T>& to); 00345 00346 // Proxy -> T 00347 template <typename P, typename T> 00348 void 00349 from_to_(const Proxy<P>& from, T& to); 00350 00351 00352 // Gpoint -> algebra::vec. 00353 template <typename P, unsigned n, typename T> 00354 void 00355 from_to_(const Gpoint<P>& from, algebra::vec<n,T>& to); 00356 00357 // Gpoint -> delta-point 00358 template <typename P> 00359 void 00360 from_to_(const Gpoint<P>& from, mln_delta(P)& to); 00361 00362 00363 // Image -> Site_Set. 00364 template <typename I, typename S> 00365 void 00366 from_to_(const Image<I>& from, Site_Set<S>& to); 00367 00368 // Image -> w_window 00369 template <typename I, typename D, typename W> 00370 void 00371 from_to_(const Image<I>& from, w_window<D,W>& to); 00372 00373 00374 // neighb<W> -> W 00375 template <typename W> 00376 void 00377 from_to_(const mln::neighb<W>& from, W& to); 00378 00379 // W -> neighb<W> 00380 template <typename W> 00381 void 00382 from_to_(const W& from, mln::neighb<W>& to); 00383 00384 00385 // Window -> Image 00386 template <typename W, typename I> 00387 void 00388 from_to_(const Window<W>& from, Image<I>& to); 00389 00390 00391 // w_window -> Image 00392 template <typename D, typename W, typename I> 00393 void 00394 from_to_(const w_window<D,W>& from, Image<I>& to); 00395 00396 00397 00398 // util::array<T> -> fun::i2v::array<T> 00399 template <typename T> 00400 void 00401 from_to_(const util::array<T>& from, fun::i2v::array<T>& to); 00402 00403 // util::array<T> -> fun::i2v::array<U> 00404 template <typename T, typename U> 00405 void 00406 from_to_(const util::array<T>& from, fun::i2v::array<U>& to); 00407 00408 // std::vector<T> -> fun::i2v::array<T> 00409 template <typename T> 00410 void 00411 from_to_(const std::vector<T>& from, fun::i2v::array<T>& to); 00412 00413 // std::vector<T> -> fun::i2v::array<U> 00414 template <typename T, typename U> 00415 void 00416 from_to_(const std::vector<T>& from, fun::i2v::array<U>& to); 00417 00418 // util::array<T1> -> util::array<T2> 00419 template <typename T1, typename T2> 00420 void 00421 from_to_(const util::array<T1>& from, util::array<T2>& to); 00422 00423 00424 00425 // util::array<T1> -> util::array<T2> 00426 template <typename T1, typename T2> 00427 void 00428 from_to_(const util::array<T1>& from, util::array<T2>& to); 00429 00430 // fun::i2v::array<T1> -> util::array<T2> 00431 template <typename T1, typename T2> 00432 void 00433 from_to_(const fun::i2v::array<T1>& from, util::array<T2>& to); 00434 00435 00436 // Accumulator<A> -> mln_result(A) 00437 template <typename A> 00438 void 00439 from_to_(const Accumulator<A>& from, mln_result(A)& to); 00440 00441 00442 00443 // Site_Set -> Image. 00444 template <typename S, typename I> 00445 void 00446 from_to_(const Site_Set<S>& from, Image<I>& to); 00447 00448 // Site_Set -> std::set 00449 template <typename S, typename P, typename C_> 00450 void 00451 from_to_(const Site_Set<S>& from, std::set<P,C_>& to); 00452 00453 // std::set -> Site_Set 00454 template <typename P, typename C_, typename S> 00455 void 00456 from_to_(const std::set<P,C_>& from, Site_Set<S>& to); 00457 00458 // histo::array -> image1d 00459 template <typename V, typename T> 00460 void 00461 from_to_(const histo::array<V>& from, image1d<T>& to); 00462 00463 // util::array -> image1d 00464 template <typename V, typename T> 00465 void 00466 from_to_(const util::array<V>& from, image1d<T>& to); 00467 00468 // util::couple<T, U> -> util::couple<V, W> 00469 template <typename T, typename U, typename V, typename W> 00470 void 00471 from_to_(const util::couple<T, U>& from, util::couple<V, W>& to) 00472 { 00473 from_to(from.first(), to.first()); 00474 from_to(from.second(), to.second()); 00475 } 00476 00477 // util::object_id<Tag,V> -> V. 00478 template <typename Tag, typename V> 00479 void from_to_(const util::object_id<Tag,V>& from, V& to_); 00480 00481 } // end of namespace mln::convert::over_load 00482 00483 } // end of namespace mln::convert 00484 00485 } // end of namespace mln 00486 00487 00488 #endif // ! MLN_CONVERT_FROM_TO_HXX