Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
openmp_vigra.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013, 2014 Christoph L. Spiel
3  *
4  * This file is part of Enblend.
5  *
6  * Enblend is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Enblend is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Enblend; if not, write to the Free Software
18  * <http://www.gnu.org/licenses/>.
19  */
20 #ifndef OPENMP_VIGRA_H_INCLUDED_
21 #define OPENMP_VIGRA_H_INCLUDED_
22 
23 #include <vigra/diff2d.hxx>
24 #include <vigra/initimage.hxx>
25 #include <vigra/inspectimage.hxx>
26 #include <vigra/transformimage.hxx>
27 #include <vigra/combineimages.hxx>
28 #include <vigra/convolution.hxx>
29 
30 #ifdef _OPENMP
31 #define OPENMP
32 #endif
33 
34 namespace vigra
35 {
36  namespace omp
37  {
38 #ifdef OPENMP
39  template <class SrcImageIterator1, class SrcAccessor1,
40  class SrcImageIterator2, class SrcAccessor2,
41  class DestImageIterator, class DestAccessor,
42  class Functor>
43  inline void
44  combineTwoImages(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
45  SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
46  DestImageIterator dest_upperleft, DestAccessor dest_acc,
47  const Functor& functor)
48  {
49 #pragma omp parallel
50  {
51  const vigra::Size2D size(src1_lowerright - src1_upperleft);
52  Functor f(functor);
53 
54 #pragma omp for schedule(guided) nowait
55  for (int y = 0; y < size.y; ++y)
56  {
57  const vigra::Diff2D begin(0, y);
58  const vigra::Diff2D end(size.x, y + 1);
59 
60  vigra::combineTwoImages(src1_upperleft + begin, src1_upperleft + end, src1_acc,
61  src2_upperleft + begin, src2_acc,
62  dest_upperleft + begin, dest_acc,
63  f);
64  }
65  } // omp parallel
66  }
67 
68 
69  template <class SrcImageIterator1, class SrcAccessor1,
70  class SrcImageIterator2, class SrcAccessor2,
71  class MaskImageIterator, class MaskAccessor,
72  class DestImageIterator, class DestAccessor,
73  class Functor>
74  inline void
75  combineTwoImagesIf(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
76  SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
77  MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
78  DestImageIterator dest_upperleft, DestAccessor dest_acc,
79  const Functor& functor)
80  {
81 #pragma omp parallel
82  {
83  const vigra::Size2D size(src1_lowerright - src1_upperleft);
84  Functor f(functor);
85 
86 #pragma omp for schedule(guided) nowait
87  for (int y = 0; y < size.y; ++y)
88  {
89  const vigra::Diff2D begin(0, y);
90  const vigra::Diff2D end(size.x, y + 1);
91 
92  vigra::combineTwoImagesIf(src1_upperleft + begin, src1_upperleft + end, src1_acc,
93  src2_upperleft + begin, src2_acc,
94  mask_upperleft + begin, mask_acc,
95  dest_upperleft + begin, dest_acc,
96  f);
97  }
98  } // omp parallel
99  }
100 
101 
102  template <class SrcImageIterator1, class SrcAccessor1,
103  class SrcImageIterator2, class SrcAccessor2,
104  class SrcImageIterator3, class SrcAccessor3,
105  class DestImageIterator, class DestAccessor,
106  class Functor>
107  inline void
108  combineThreeImages(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
109  SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
110  SrcImageIterator3 src3_upperleft, SrcAccessor3 src3_acc,
111  DestImageIterator dest_upperleft, DestAccessor dest_acc,
112  const Functor& functor)
113  {
114 #pragma omp parallel
115  {
116  const vigra::Size2D size(src1_lowerright - src1_upperleft);
117  Functor f(functor);
118 
119 #pragma omp for schedule(guided) nowait
120  for (int y = 0; y < size.y; ++y)
121  {
122  const vigra::Diff2D begin(0, y);
123  const vigra::Diff2D end(size.x, y + 1);
124 
125  vigra::combineThreeImages(src1_upperleft + begin, src1_upperleft + end, src1_acc,
126  src2_upperleft + begin, src2_acc,
127  src3_upperleft + begin, src3_acc,
128  dest_upperleft + begin, dest_acc,
129  f);
130  }
131  } // omp parallel
132  }
133 
134 
135  template <class SrcImageIterator, class SrcAccessor,
136  class DestImageIterator, class DestAccessor>
137  inline void
138  copyImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
139  DestImageIterator dest_upperleft, DestAccessor dest_acc)
140  {
141 #pragma omp parallel
142  {
143  const vigra::Size2D size(src_lowerright - src_upperleft);
144 
145 #pragma omp for schedule(guided) nowait
146  for (int y = 0; y < size.y; ++y)
147  {
148  const vigra::Diff2D begin(0, y);
149  const vigra::Diff2D end(size.x, y + 1);
150 
151  vigra::copyImage(src_upperleft + begin, src_upperleft + end, src_acc,
152  dest_upperleft + begin, dest_acc);
153  }
154  } // omp parallel
155  }
156 
157 
158  template <class SrcImageIterator, class SrcAccessor,
159  class MaskImageIterator, class MaskAccessor,
160  class DestImageIterator, class DestAccessor>
161  inline void
162  copyImageIf(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
163  MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
164  DestImageIterator dest_upperleft, DestAccessor dest_acc)
165  {
166 #pragma omp parallel
167  {
168  const vigra::Size2D size(src_lowerright - src_upperleft);
169 
170 #pragma omp for schedule(guided) nowait
171  for (int y = 0; y < size.y; ++y)
172  {
173  const vigra::Diff2D begin(0, y);
174  const vigra::Diff2D end(size.x, y + 1);
175 
176  vigra::copyImageIf(src_upperleft + begin, src_upperleft + end, src_acc,
177  mask_upperleft + begin, mask_acc,
178  dest_upperleft + begin, dest_acc);
179  }
180  } // omp parallel
181  }
182 
183 
184  template <class SrcImageIterator, class SrcAccessor,
185  class DestImageIterator, class DestAccessor,
186  class Functor>
187  inline void
188  transformImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
189  DestImageIterator dest_upperleft, DestAccessor dest_acc,
190  const Functor& functor)
191  {
192 #pragma omp parallel
193  {
194  const vigra::Size2D size(src_lowerright - src_upperleft);
195  Functor f(functor);
196 
197 #pragma omp for schedule(guided) nowait
198  for (int y = 0; y < size.y; ++y)
199  {
200  const vigra::Diff2D begin(0, y);
201  const vigra::Diff2D end(size.x, y + 1);
202 
203  vigra::transformImage(src_upperleft + begin, src_upperleft + end, src_acc,
204  dest_upperleft + begin, dest_acc,
205  f);
206  }
207  } // omp parallel
208  }
209 
210 
211  template <class SrcImageIterator, class SrcAccessor,
212  class MaskImageIterator, class MaskAccessor,
213  class DestImageIterator, class DestAccessor,
214  class Functor>
215  inline void
216  transformImageIf(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
217  MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
218  DestImageIterator dest_upperleft, DestAccessor dest_acc,
219  const Functor& functor)
220  {
221 #pragma omp parallel
222  {
223  const vigra::Size2D size(src_lowerright - src_upperleft);
224  Functor f(functor);
225 
226 #pragma omp for schedule(guided) nowait
227  for (int y = 0; y < size.y; ++y)
228  {
229  const vigra::Diff2D begin(0, y);
230  const vigra::Diff2D end(size.x, y + 1);
231 
232  vigra::transformImageIf(src_upperleft + begin, src_upperleft + end, src_acc,
233  mask_upperleft + begin, mask_acc,
234  dest_upperleft + begin, dest_acc,
235  f);
236  }
237  } // omp parallel
238  }
239 
240 
241 #else
242 
243 
244  template <class SrcImageIterator1, class SrcAccessor1,
245  class SrcImageIterator2, class SrcAccessor2,
246  class DestImageIterator, class DestAccessor,
247  class Functor>
248  inline void
249  combineTwoImages(SrcImageIterator1 src1_upperleft,
250  SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
251  SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
252  DestImageIterator dest_upperleft, DestAccessor dest_acc,
253  const Functor& func)
254  {
255  vigra::combineTwoImages(src1_upperleft, src1_lowerright, src1_acc,
256  src2_upperleft, src2_acc,
257  dest_upperleft, dest_acc,
258  func);
259  }
260 
261 
262  template <class SrcImageIterator1, class SrcAccessor1,
263  class SrcImageIterator2, class SrcAccessor2,
264  class MaskImageIterator, class MaskAccessor,
265  class DestImageIterator, class DestAccessor,
266  class Functor>
267  inline void
268  combineTwoImagesIf(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
269  SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
270  MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
271  DestImageIterator dest_upperleft, DestAccessor dest_acc,
272  const Functor& func)
273  {
274  vigra::combineTwoImagesIf(src1_upperleft, src1_lowerright, src1_acc,
275  src2_upperleft, src2_acc,
276  mask_upperleft, mask_acc,
277  dest_upperleft, dest_acc,
278  func);
279  }
280 
281 
282  template <class SrcImageIterator1, class SrcAccessor1,
283  class SrcImageIterator2, class SrcAccessor2,
284  class SrcImageIterator3, class SrcAccessor3,
285  class DestImageIterator, class DestAccessor,
286  class Functor>
287  inline void
288  combineThreeImages(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
289  SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
290  SrcImageIterator3 src3_upperleft, SrcAccessor3 src3_acc,
291  DestImageIterator dest_upperleft, DestAccessor dest_acc,
292  const Functor& func)
293  {
294  vigra::combineThreeImages(src1_upperleft, src1_lowerright, src1_acc,
295  src2_upperleft, src2_acc,
296  src3_upperleft, src3_acc,
297  dest_upperleft, dest_acc,
298  func);
299  }
300 
301 
302  template <class SrcImageIterator, class SrcAccessor,
303  class DestImageIterator, class DestAccessor>
304  inline void
305  copyImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
306  DestImageIterator dest_upperleft, DestAccessor dest_acc)
307  {
308  vigra::copyImage(src_upperleft, src_lowerright, src_acc, dest_upperleft, dest_acc);
309  }
310 
311 
312  template <class SrcImageIterator, class SrcAccessor,
313  class MaskImageIterator, class MaskAccessor,
314  class DestImageIterator, class DestAccessor>
315  inline void
316  copyImageIf(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
317  MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
318  DestImageIterator dest_upperleft, DestAccessor dest_acc)
319  {
320  vigra::copyImageIf(src_upperleft, src_lowerright, src_acc,
321  mask_upperleft, mask_acc,
322  dest_upperleft, dest_acc);
323  }
324 
325 
326  template <class SrcImageIterator, class SrcAccessor,
327  class DestImageIterator, class DestAccessor,
328  class Functor>
329  inline void
330  transformImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
331  DestImageIterator dest_upperleft, DestAccessor dest_acc,
332  const Functor& func)
333  {
334  vigra::transformImage(src_upperleft, src_lowerright, src_acc,
335  dest_upperleft, dest_acc,
336  func);
337  }
338 
339 
340  template <class SrcImageIterator, class SrcAccessor,
341  class MaskImageIterator, class MaskAccessor,
342  class DestImageIterator, class DestAccessor,
343  class Functor>
344  inline void
345  transformImageIf(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
346  MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
347  DestImageIterator dest_upperleft, DestAccessor dest_acc,
348  const Functor& func)
349  {
350  vigra::transformImageIf(src_upperleft, src_lowerright, src_acc,
351  mask_upperleft, mask_acc,
352  dest_upperleft, dest_acc,
353  func);
354  }
355 
356 #endif // OPENMP
357 
358 
359  //
360  // Argument Object Factory versions
361  //
362 
363  template <class SrcImageIterator1, class SrcAccessor1,
364  class SrcImageIterator2, class SrcAccessor2,
365  class DestImageIterator, class DestAccessor,
366  class Functor>
367  inline void
368  combineTwoImages(vigra::triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
369  vigra::pair<SrcImageIterator2, SrcAccessor2> src2,
370  vigra::pair<DestImageIterator, DestAccessor> dest,
371  const Functor& functor)
372  {
373  vigra::omp::combineTwoImages(src1.first, src1.second, src1.third,
374  src2.first, src2.second,
375  dest.first, dest.second,
376  functor);
377  }
378 
379 
380  template <class SrcImageIterator1, class SrcAccessor1,
381  class SrcImageIterator2, class SrcAccessor2,
382  class MaskImageIterator, class MaskAccessor,
383  class DestImageIterator, class DestAccessor,
384  class Functor>
385  inline void
386  combineTwoImagesIf(vigra::triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
387  vigra::pair<SrcImageIterator2, SrcAccessor2> src2,
388  vigra::pair<MaskImageIterator, MaskAccessor> mask,
389  vigra::pair<DestImageIterator, DestAccessor> dest,
390  const Functor& functor)
391  {
392  vigra::omp::combineTwoImagesIf(src1.first, src1.second, src1.third,
393  src2.first, src2.second,
394  mask.first, mask.second,
395  dest.first, dest.second,
396  functor);
397  }
398 
399 
400  template <class SrcImageIterator1, class SrcAccessor1,
401  class SrcImageIterator2, class SrcAccessor2,
402  class SrcImageIterator3, class SrcAccessor3,
403  class DestImageIterator, class DestAccessor,
404  class Functor>
405  inline void
406  combineThreeImages(vigra::triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
407  vigra::pair<SrcImageIterator2, SrcAccessor2> src2,
408  vigra::pair<SrcImageIterator3, SrcAccessor3> src3,
409  vigra::pair<DestImageIterator, DestAccessor> dest,
410  const Functor& functor)
411  {
412  vigra::omp::combineThreeImages(src1.first, src1.second, src1.third,
413  src2.first, src2.second,
414  src3.first, src3.second,
415  dest.first, dest.second,
416  functor);
417  }
418 
419 
420  template <class SrcImageIterator, class SrcAccessor,
421  class DestImageIterator, class DestAccessor,
422  class Functor>
423  inline void
424  transformImage(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
425  vigra::pair<DestImageIterator, DestAccessor> dest,
426  const Functor& functor)
427  {
428  vigra::omp::transformImage(src.first, src.second, src.third,
429  dest.first, dest.second,
430  functor);
431  }
432 
433 
434  template <class SrcImageIterator, class SrcAccessor,
435  class DestImageIterator, class DestAccessor>
436  inline void
437  copyImage(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
438  vigra::pair<DestImageIterator, DestAccessor> dest)
439  {
440  vigra::omp::copyImage(src.first, src.second, src.third,
441  dest.first, dest.second);
442  }
443 
444 
445  template <class SrcImageIterator, class SrcAccessor,
446  class MaskImageIterator, class MaskAccessor,
447  class DestImageIterator, class DestAccessor>
448  inline void
449  copyImageIf(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
450  vigra::pair<MaskImageIterator, MaskAccessor> mask,
451  vigra::pair<DestImageIterator, DestAccessor> dest)
452  {
453  vigra::omp::copyImageIf(src.first, src.second, src.third,
454  mask.first, mask.second,
455  dest.first, dest.second);
456  }
457 
458 
459  template <class SrcImageIterator, class SrcAccessor,
460  class MaskImageIterator, class MaskAccessor,
461  class DestImageIterator, class DestAccessor,
462  class Functor>
463  inline void
464  transformImageIf(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
465  vigra::pair<MaskImageIterator, MaskAccessor> mask,
466  vigra::pair<DestImageIterator, DestAccessor> dest,
467  const Functor& functor)
468  {
469  vigra::omp::transformImageIf(src.first, src.second, src.third,
470  mask.first, mask.second,
471  dest.first, dest.second,
472  functor);
473  }
474 
475  } // namespace omp
476 } // namespace vigra
477 
478 
479 #endif // OPENMP_VIGRA_H_INCLUDED_
480 
481 // Local Variables:
482 // mode: c++
483 // End:
void transformImage(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, vigra::triple< DestImageIterator, DestImageIterator, DestAccessor > dest, std::pair< AlphaImageIterator, AlphaAccessor > alpha, vigra::Diff2D destUL, TRANSFORM &transform, PixelTransform &pixelTransform, bool warparound, Interpolator interpol, AppBase::ProgressDisplay *progress, bool singleThreaded=false)
Transform an image into the panorama.
void copyImageIf(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc, MaskImageIterator mask_upperleft, MaskAccessor mask_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc)
Definition: openmp_vigra.h:316
void combineThreeImages(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc, SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc, SrcImageIterator3 src3_upperleft, SrcAccessor3 src3_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc, const Functor &func)
Definition: openmp_vigra.h:288
void combineTwoImages(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc, SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc, const Functor &func)
Definition: openmp_vigra.h:249
void transformImageIf(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc, MaskImageIterator mask_upperleft, MaskAccessor mask_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc, const Functor &func)
Definition: openmp_vigra.h:345
void combineTwoImagesIf(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc, SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc, MaskImageIterator mask_upperleft, MaskAccessor mask_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc, const Functor &func)
Definition: openmp_vigra.h:268
void transformImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc, const Functor &func)
Definition: openmp_vigra.h:330
void copyImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc)
Definition: openmp_vigra.h:305