from_to.hxx 12.4 KB
Newer Older
1
2
// Copyright (C) 2008, 2009, 2010 EPITA Research and Development
// Laboratory (LRDE)
3
//
4
// This file is part of Olena.
5
//
6
7
8
9
10
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
11
12
13
14
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
16
// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
17
18
//
// As a special exception, you may use this file as part of a free
19
// software project without restriction.  Specifically, if other files
20
// instantiate templates or use macros or inline functions from this
21
22
23
24
25
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License.  This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
26
27
28
29
30
31
32
33
34

#ifndef MLN_CONVERT_FROM_TO_HXX
# define MLN_CONVERT_FROM_TO_HXX

/// \internal \file mln/convert/from_to.hxx

// All overloaded "convert::from_to" routines have to be declared in
// the present file.  It allows for *deferred* use of these routines.

35
36
# include <mln/core/def/all.hh>
# include <mln/core/grids.hh>
37
# include <mln/util/couple.hh>
38

39
40
//FIXME: have a forward declaration.
# include <vector>
41
42
# include <set>

43
44
45
46
47
48
49

namespace mln
{


  // Forward declarations.

Guillaume Lazzara's avatar
Guillaume Lazzara committed
50
  template <typename E> struct Accumulator;
51
52
53
  template <typename E> struct Gdpoint;
  template <typename E> struct Gpoint;
  template <typename E> struct Image;
54
55
56
57
  template <typename E> struct Object;
  template <typename E> struct Proxy;
  template <typename E> struct Site_Set;
  template <typename E> struct Value;
58
59
60
61
62
  template <typename E> struct Weighted_Window;
  template <typename E> struct Window;

  template <typename G, typename C> struct dpoint;
  template <typename G, typename C> struct point;
63
64
65

  template <typename D> class neighb;
  template <typename D> class window;
66
  template <typename D, typename W> class w_window;
67

68
69
  template <typename T> struct image1d;

70
71
72
73
74
  namespace algebra {
    template <unsigned n, typename T> class vec;
    template <unsigned d, typename C> class h_vec;
  }

75
76
77
78
79
80
  namespace fun {
    namespace i2v {
      template <typename T> class array;
    }
  }

81
82
83
84
  namespace histo {
    template <typename T> struct array;
  }

85
86
87
88
  namespace util {
    template <typename T> class array;
  }

89
  namespace value {
90
    namespace qt { struct rgb32; }
91
    template <unsigned n> struct rgb;
92
93
    template <typename H, typename S, typename L> class hsl_;
    template <unsigned n> struct int_u;
Guillaume Lazzara's avatar
Guillaume Lazzara committed
94
    template <unsigned n> struct label;
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  }

  // end of Forward declarations.



  // convert::to

  namespace convert
  {

    template <typename T, typename O>
    T
    to(const O& from);

  } // end of namespace mln::convert



  // convert::from_to

  namespace convert
  {

Guillaume Lazzara's avatar
Guillaume Lazzara committed
119
120
121
122
123
124
125
    // Facade

    template <typename F, typename T>
    void
    from_to(const F& from, T& to);


Guillaume Lazzara's avatar
Guillaume Lazzara committed
126
127
    namespace over_load
    {
128

Guillaume Lazzara's avatar
Guillaume Lazzara committed
129
130
131
132
133
      // Guard.
      template <typename F, typename T>
      void
      from_to_(const Object<F>&, Object<T>&);
      // end of Guard.
134

Guillaume Lazzara's avatar
Guillaume Lazzara committed
135
136
137
138
139
140
141
142
143
144
      // Object -> Object
      template <typename T>
      void
      from_to_(const Object<T>& from, Object<T>& to);

      // Object -> Object
      template <typename T>
      void
      from_to_(const T& from, T& to);

145
146
147
148
149
      // point -> point.
      template <typename G, typename C1, typename C2>
      inline
      void
      from_to_(const point<G,C1>& from, point<G,C2>& to);
150

151
152
153
154
155
156
157
158
159
160
      // 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);

Guillaume Lazzara's avatar
Guillaume Lazzara committed
161
162
163
164
      // algebra::vec -> Gpoint.
      template <unsigned n, typename T, typename P>
      void
      from_to_(const algebra::vec<n,T>& from, Gpoint<P>& to_);
165

Guillaume Lazzara's avatar
Guillaume Lazzara committed
166
167
168
169
      // algebra::vec -> rgb.
      template <typename T, unsigned m>
      void
      from_to_(const algebra::vec<3,T>& from, value::rgb<m>& to);
170

171

Guillaume Lazzara's avatar
Guillaume Lazzara committed
172
173
174
175
      // bool -> rgb.
      template <unsigned m>
      void
      from_to_(bool from, value::rgb<m>& to);
176

Guillaume Lazzara's avatar
Guillaume Lazzara committed
177
      // rgb32 -> bool
178
179
180
      void
      from_to_(const value::qt::rgb32& from, bool& to);

Guillaume Lazzara's avatar
Guillaume Lazzara committed
181
182
183
184
      // bool -> rgb32
      void
      from_to_(const bool& from, value::qt::rgb32& to);

185
186
187
188
      // int_u -> rgb.
      template <unsigned m>
      void from_to_(const value::int_u<m>& from, value::rgb<m>& to);

189
190
191
192
      // int_u -> qt::rgb32.
      template <unsigned m>
      void from_to_(const value::int_u<m>& from, value::qt::rgb32& to);

Guillaume Lazzara's avatar
Guillaume Lazzara committed
193
194
195
196
      // int_u -> label
      template <unsigned n>
      void from_to_(const value::int_u<n>& from, value::label<n>& to_);

197
198
199
200
      // int_u -> unsigned
      template <unsigned n>
      void from_to_(const value::int_u<n>& from, unsigned& to_);

Guillaume Lazzara's avatar
Guillaume Lazzara committed
201
202
203
204
205
      // int_u -> bool.
      template <unsigned n>
      void
      from_to_(const value::int_u<n>& from, bool& to_);

206
207
208
209
210
211
212
213
      // int_u -> float
      template <unsigned n>
      void from_to_(const value::int_u<n>& from, float& to_);

      // int_u -> double
      template <unsigned n>
      void from_to_(const value::int_u<n>& from, double& to_);

214
215
216
217
218
219
      // label -> int_u.
      template <unsigned n>
      void
      from_to_(const value::label<n>& from, value::int_u<n>& to_);

      // label -> bool
Guillaume Lazzara's avatar
Guillaume Lazzara committed
220
221
222
      template <unsigned n>
      void from_to_(const value::label<n>& from, bool& to_);

Guillaume Lazzara's avatar
Guillaume Lazzara committed
223
224
225
226
227
      // int_u<n> -> label<m> with n < m
      template <unsigned n, unsigned m>
      void
      from_to_(const value::int_u<n>& from, value::label<m>& to_);

228
229
230
231
232
233
234
235
      // hsl -> rgb8.
      template <typename H, typename S, typename L>
      void from_to_(const value::hsl_<H,S,L>&, value::rgb<8>& to);

      // hsl -> rgb16.
      template <typename H, typename S, typename L>
      void from_to_(const value::hsl_<H,S,L>&, value::rgb<16>& to);

236
237
238
      // hsl -> qt::rgb32.
      template <typename H, typename S, typename L>
      void from_to_(const value::hsl_<H,S,L>&, value::qt::rgb32& to);
239
240
241

      // rgb to hsl
      void
242
      from_to_(const value::rgb<16>& from, value::hsl_<float,float,float>& to);
243
244
245

      // rgb to hsl
      void
246
      from_to_(const value::rgb<8>& from, value::hsl_<float,float,float>& to);
247

Guillaume Lazzara's avatar
Guillaume Lazzara committed
248
249
250
251
      // rgb -> bool.
      template <unsigned m>
      void from_to_(const value::rgb<m>& from, bool& to);

252

Guillaume Lazzara's avatar
Guillaume Lazzara committed
253
254
255
256
      // C-array -> Image.
      template <typename V, unsigned S, typename I>
      void
      from_to_(const V (&values)[S], Image<I>& to);
257

Guillaume Lazzara's avatar
Guillaume Lazzara committed
258
259
260
261
      // C-array -> w_window
      template <typename V, unsigned S, typename D, typename W>
      void
      from_to_(const V (&weight)[S], w_window<D,W>& to);
262
263


Guillaume Lazzara's avatar
Guillaume Lazzara committed
264
265
266
267
268
      // C-array -> window2d
      template <unsigned S>
      void
      from_to_(const bool (&values)[S],
	       window< dpoint<grid::square, def::coord> >& win);
269

Guillaume Lazzara's avatar
Guillaume Lazzara committed
270
271
272
273
      template <unsigned R, unsigned C>
      void
      from_to_(const bool (&values)[R][C],
	       window< dpoint<grid::square, def::coord> >& win);
274

275
276
277
278
279
280
281
282

      // C-array -> window3d
      template <unsigned S>
      void
      from_to_(const bool (&values)[S],
	       window< dpoint<grid::cube, def::coord> >& win);


Guillaume Lazzara's avatar
Guillaume Lazzara committed
283
284
285
286
287
      // C-array -> neighb2d
      template <unsigned S>
      void
      from_to_(const bool (&values)[S],
	       neighb< window< dpoint<grid::square, def::coord> > >& nbh);
288

Guillaume Lazzara's avatar
Guillaume Lazzara committed
289
290
291
292
      template <unsigned R, unsigned C>
      void
      from_to_(bool const (&values)[R][C],
	       neighb< window< dpoint<grid::square, def::coord> > >& nbh);
293

294
295
296
297
298
299
300
301
302

      // C-array -> neighb3d
      template <unsigned S>
      void
      from_to_(const bool (&values)[S],
	       neighb< window< dpoint<grid::cube, def::coord> > >& nbh);



Guillaume Lazzara's avatar
Guillaume Lazzara committed
303
304
305
306
      // Gdpoint -> point
      template <typename D>
      void
      from_to_(const Gdpoint<D>& from, mln_site(D)& to);
307
308


Guillaume Lazzara's avatar
Guillaume Lazzara committed
309
310
311
312
      // Value -> Value
      template <typename F, typename T>
      void
      from_to_(const Value<F>& from, Value<T>& to);
313

314
315
316
317
318
319
320
321
322
323
324
325
326
      // double-> Value
      template <typename V>
      void
      from_to_(const double& from, Value<V>& to);

      // double-> unsigned
      void
      from_to_(const double& from, unsigned& to);

      // double-> int
      void
      from_to_(const double& from, int&	to);

Guillaume Lazzara's avatar
Guillaume Lazzara committed
327
328
329
330
      // float -> Value
      template <typename V>
      void
      from_to_(const float& from, Value<V>& to);
331

Guillaume Lazzara's avatar
Guillaume Lazzara committed
332
333
334
335
336
337
338
339
      // float -> unsigned
      void
      from_to_(const float& from, unsigned& to);

      // float -> int
      void
      from_to_(const float& from, int& to);

Guillaume Lazzara's avatar
Guillaume Lazzara committed
340
341
342
343
      // int -> Value
      template <typename T>
      void
      from_to_(const int& from, Value<T>& to);
344

Guillaume Lazzara's avatar
Guillaume Lazzara committed
345
346
347
348
      // Proxy -> T
      template <typename P, typename T>
      void
      from_to_(const Proxy<P>& from, T& to);
349

Thierry Geraud's avatar
Thierry Geraud committed
350

Guillaume Lazzara's avatar
Guillaume Lazzara committed
351
352
353
354
      // Gpoint -> algebra::vec.
      template <typename P, unsigned n, typename T>
      void
      from_to_(const Gpoint<P>& from, algebra::vec<n,T>& to);
355

Guillaume Lazzara's avatar
Guillaume Lazzara committed
356
357
358
359
      // Gpoint -> delta-point
      template <typename P>
      void
      from_to_(const Gpoint<P>& from, mln_delta(P)& to);
360

Thierry Geraud's avatar
Thierry Geraud committed
361

Guillaume Lazzara's avatar
Guillaume Lazzara committed
362
363
364
365
      // Image -> Site_Set.
      template <typename I, typename S>
      void
      from_to_(const Image<I>& from, Site_Set<S>& to);
366

Guillaume Lazzara's avatar
Guillaume Lazzara committed
367
368
369
370
      // Image -> w_window
      template <typename I, typename D, typename W>
      void
      from_to_(const Image<I>& from, w_window<D,W>& to);
371

372

Guillaume Lazzara's avatar
Guillaume Lazzara committed
373
374
375
376
      // neighb<W> -> W
      template <typename W>
      void
      from_to_(const mln::neighb<W>& from, W& to);
377

Guillaume Lazzara's avatar
Guillaume Lazzara committed
378
379
380
381
      // W -> neighb<W>
      template <typename W>
      void
      from_to_(const W& from, mln::neighb<W>& to);
382
383


Guillaume Lazzara's avatar
Guillaume Lazzara committed
384
385
386
387
      // Window -> Image
      template <typename W, typename I>
      void
      from_to_(const Window<W>& from, Image<I>& to);
388
389


Guillaume Lazzara's avatar
Guillaume Lazzara committed
390
391
392
393
      // w_window -> Image
      template <typename D, typename W, typename I>
      void
      from_to_(const w_window<D,W>& from, Image<I>& to);
394
395


Guillaume Lazzara's avatar
Guillaume Lazzara committed
396

Guillaume Lazzara's avatar
Guillaume Lazzara committed
397
398
399
400
      // util::array<T> -> fun::i2v::array<T>
      template <typename T>
      void
      from_to_(const util::array<T>& from, fun::i2v::array<T>& to);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
401

Guillaume Lazzara's avatar
Guillaume Lazzara committed
402
403
404
405
406
      // util::array<T> -> fun::i2v::array<U>
      template <typename T, typename U>
      void
      from_to_(const util::array<T>& from, fun::i2v::array<U>& to);

Guillaume Lazzara's avatar
Guillaume Lazzara committed
407
408
409
410
      // std::vector<T> -> fun::i2v::array<T>
      template <typename T>
      void
      from_to_(const std::vector<T>& from, fun::i2v::array<T>& to);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
411

Guillaume Lazzara's avatar
Guillaume Lazzara committed
412
413
414
415
416
417
418
419
420
421
422
423
      // std::vector<T> -> fun::i2v::array<U>
      template <typename T, typename U>
      void
      from_to_(const std::vector<T>& from, fun::i2v::array<U>& to);

      // util::array<T1> -> util::array<T2>
      template <typename T1, typename T2>
      void
      from_to_(const util::array<T1>& from, util::array<T2>& to);



Guillaume Lazzara's avatar
Guillaume Lazzara committed
424
425
426
427
      // util::array<T1> -> util::array<T2>
      template <typename T1, typename T2>
      void
      from_to_(const util::array<T1>& from, util::array<T2>& to);
428

429
430
431
432
      // fun::i2v::array<T1> -> util::array<T2>
      template <typename T1, typename T2>
      void
      from_to_(const fun::i2v::array<T1>& from, util::array<T2>& to);
433

Guillaume Lazzara's avatar
Guillaume Lazzara committed
434

Guillaume Lazzara's avatar
Guillaume Lazzara committed
435
436
437
438
439
440
      // Accumulator<A> -> mln_result(A)
      template <typename A>
      void
      from_to_(const Accumulator<A>& from, mln_result(A)& to);


441
442
443
444
445
446

      // Site_Set -> Image.
      template <typename S, typename I>
      void
      from_to_(const Site_Set<S>& from, Image<I>& to);

Guillaume Lazzara's avatar
Guillaume Lazzara committed
447
      // Site_Set -> std::set
448
      template <typename S, typename P, typename C_>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
449
      void
450
      from_to_(const Site_Set<S>& from, std::set<P,C_>& to);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
451
452

      // std::set -> Site_Set
453
      template <typename P, typename C_, typename S>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
454
      void
455
      from_to_(const std::set<P,C_>& from, Site_Set<S>& to);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
456

457
458
459
460
461
      // histo::array -> image1d
      template <typename V, typename T>
      void
      from_to_(const histo::array<V>& from, image1d<T>& to);

462
463
464
465
466
      // util::array -> image1d
      template <typename V, typename T>
      void
      from_to_(const util::array<V>& from, image1d<T>& to);

467
468
469
470
471
472
473
474
475
      // util::couple<T, U> -> util::couple<V, W>
      template <typename T, typename U, typename V, typename W>
      void
      from_to_(const util::couple<T, U>& from, util::couple<V, W>& to)
      {
        from_to(from.first(), to.first());
        from_to(from.second(), to.second());
      }

Guillaume Lazzara's avatar
Guillaume Lazzara committed
476
    } // end of namespace mln::convert::over_load
477

478
479
480
481
482
483
  } // end of namespace mln::convert

} // end of namespace mln


#endif // ! MLN_CONVERT_FROM_TO_HXX