openmp_vigra.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2013, 2014 Christoph L. Spiel
00003  *
00004  * This file is part of Enblend.
00005  *
00006  * Enblend is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * Enblend is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with Enblend; if not, write to the Free Software
00018  * <http://www.gnu.org/licenses/>.
00019  */
00020 #ifndef OPENMP_VIGRA_H_INCLUDED_
00021 #define OPENMP_VIGRA_H_INCLUDED_
00022 
00023 #include <vigra/diff2d.hxx>
00024 #include <vigra/initimage.hxx>
00025 #include <vigra/inspectimage.hxx>
00026 #include <vigra/transformimage.hxx>
00027 #include <vigra/combineimages.hxx>
00028 #include <vigra/convolution.hxx>
00029 
00030 #ifdef _OPENMP
00031 #define OPENMP
00032 #endif
00033 
00034 namespace vigra
00035 {
00036     namespace omp
00037     {
00038 #ifdef OPENMP
00039         template <class SrcImageIterator1, class SrcAccessor1,
00040                   class SrcImageIterator2, class SrcAccessor2,
00041                   class DestImageIterator, class DestAccessor,
00042                   class Functor>
00043         inline void
00044         combineTwoImages(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
00045                          SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
00046                          DestImageIterator dest_upperleft, DestAccessor dest_acc,
00047                          const Functor& functor)
00048         {
00049 #pragma omp parallel
00050             {
00051                 const vigra::Size2D size(src1_lowerright - src1_upperleft);
00052                 Functor f(functor);
00053 
00054 #pragma omp for schedule(guided) nowait
00055                 for (int y = 0; y < size.y; ++y)
00056                 {
00057                     const vigra::Diff2D begin(0, y);
00058                     const vigra::Diff2D end(size.x, y + 1);
00059 
00060                     vigra::combineTwoImages(src1_upperleft + begin, src1_upperleft + end, src1_acc,
00061                                             src2_upperleft + begin, src2_acc,
00062                                             dest_upperleft + begin, dest_acc,
00063                                             f);
00064                 }
00065             } // omp parallel
00066         }
00067 
00068 
00069         template <class SrcImageIterator1, class SrcAccessor1,
00070                   class SrcImageIterator2, class SrcAccessor2,
00071                   class MaskImageIterator, class MaskAccessor,
00072                   class DestImageIterator, class DestAccessor,
00073                   class Functor>
00074         inline void
00075         combineTwoImagesIf(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
00076                            SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
00077                            MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
00078                            DestImageIterator dest_upperleft, DestAccessor dest_acc,
00079                            const Functor& functor)
00080         {
00081 #pragma omp parallel
00082             {
00083                 const vigra::Size2D size(src1_lowerright - src1_upperleft);
00084                 Functor f(functor);
00085 
00086 #pragma omp for schedule(guided) nowait
00087                 for (int y = 0; y < size.y; ++y)
00088                 {
00089                     const vigra::Diff2D begin(0, y);
00090                     const vigra::Diff2D end(size.x, y + 1);
00091 
00092                     vigra::combineTwoImagesIf(src1_upperleft + begin, src1_upperleft + end, src1_acc,
00093                                               src2_upperleft + begin, src2_acc,
00094                                               mask_upperleft + begin, mask_acc,
00095                                               dest_upperleft + begin, dest_acc,
00096                                               f);
00097                 }
00098             } // omp parallel
00099         }
00100 
00101 
00102         template <class SrcImageIterator1, class SrcAccessor1,
00103                   class SrcImageIterator2, class SrcAccessor2,
00104                   class SrcImageIterator3, class SrcAccessor3,
00105                   class DestImageIterator, class DestAccessor,
00106                   class Functor>
00107         inline void
00108         combineThreeImages(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
00109                            SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
00110                            SrcImageIterator3 src3_upperleft, SrcAccessor3 src3_acc,
00111                            DestImageIterator dest_upperleft, DestAccessor dest_acc,
00112                            const Functor& functor)
00113         {
00114 #pragma omp parallel
00115             {
00116                 const vigra::Size2D size(src1_lowerright - src1_upperleft);
00117                 Functor f(functor);
00118 
00119 #pragma omp for schedule(guided) nowait
00120                 for (int y = 0; y < size.y; ++y)
00121                 {
00122                     const vigra::Diff2D begin(0, y);
00123                     const vigra::Diff2D end(size.x, y + 1);
00124 
00125                     vigra::combineThreeImages(src1_upperleft + begin, src1_upperleft + end, src1_acc,
00126                                               src2_upperleft + begin, src2_acc,
00127                                               src3_upperleft + begin, src3_acc,
00128                                               dest_upperleft + begin, dest_acc,
00129                                               f);
00130                 }
00131             } // omp parallel
00132         }
00133 
00134 
00135         template <class SrcImageIterator, class SrcAccessor,
00136                   class DestImageIterator, class DestAccessor>
00137         inline void
00138         copyImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
00139                   DestImageIterator dest_upperleft, DestAccessor dest_acc)
00140         {
00141 #pragma omp parallel
00142             {
00143                 const vigra::Size2D size(src_lowerright - src_upperleft);
00144 
00145 #pragma omp for schedule(guided) nowait
00146                 for (int y = 0; y < size.y; ++y)
00147                 {
00148                     const vigra::Diff2D begin(0, y);
00149                     const vigra::Diff2D end(size.x, y + 1);
00150 
00151                     vigra::copyImage(src_upperleft + begin, src_upperleft + end, src_acc,
00152                                      dest_upperleft + begin, dest_acc);
00153                 }
00154             } // omp parallel
00155         }
00156 
00157 
00158         template <class SrcImageIterator, class SrcAccessor,
00159                   class MaskImageIterator, class MaskAccessor,
00160                   class DestImageIterator, class DestAccessor>
00161         inline void
00162         copyImageIf(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
00163                     MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
00164                     DestImageIterator dest_upperleft, DestAccessor dest_acc)
00165         {
00166 #pragma omp parallel
00167             {
00168                 const vigra::Size2D size(src_lowerright - src_upperleft);
00169 
00170 #pragma omp for schedule(guided) nowait
00171                 for (int y = 0; y < size.y; ++y)
00172                 {
00173                     const vigra::Diff2D begin(0, y);
00174                     const vigra::Diff2D end(size.x, y + 1);
00175 
00176                     vigra::copyImageIf(src_upperleft + begin, src_upperleft + end, src_acc,
00177                                        mask_upperleft + begin, mask_acc,
00178                                        dest_upperleft + begin, dest_acc);
00179                 }
00180             } // omp parallel
00181         }
00182 
00183 
00184         template <class SrcImageIterator, class SrcAccessor,
00185                   class DestImageIterator, class DestAccessor,
00186                   class Functor>
00187         inline void
00188         transformImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
00189                        DestImageIterator dest_upperleft, DestAccessor dest_acc,
00190                        const Functor& functor)
00191         {
00192 #pragma omp parallel
00193             {
00194                 const vigra::Size2D size(src_lowerright - src_upperleft);
00195                 Functor f(functor);
00196 
00197 #pragma omp for schedule(guided) nowait
00198                 for (int y = 0; y < size.y; ++y)
00199                 {
00200                     const vigra::Diff2D begin(0, y);
00201                     const vigra::Diff2D end(size.x, y + 1);
00202 
00203                     vigra::transformImage(src_upperleft + begin, src_upperleft + end, src_acc,
00204                                           dest_upperleft + begin, dest_acc,
00205                                           f);
00206                 }
00207             } // omp parallel
00208         }
00209 
00210 
00211         template <class SrcImageIterator, class SrcAccessor,
00212                   class MaskImageIterator, class MaskAccessor,
00213                   class DestImageIterator, class DestAccessor,
00214                   class Functor>
00215         inline void
00216         transformImageIf(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
00217                          MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
00218                          DestImageIterator dest_upperleft, DestAccessor dest_acc,
00219                          const Functor& functor)
00220         {
00221 #pragma omp parallel
00222             {
00223                 const vigra::Size2D size(src_lowerright - src_upperleft);
00224                 Functor f(functor);
00225 
00226 #pragma omp for schedule(guided) nowait
00227                 for (int y = 0; y < size.y; ++y)
00228                 {
00229                     const vigra::Diff2D begin(0, y);
00230                     const vigra::Diff2D end(size.x, y + 1);
00231 
00232                     vigra::transformImageIf(src_upperleft + begin, src_upperleft + end, src_acc,
00233                                             mask_upperleft + begin, mask_acc,
00234                                             dest_upperleft + begin, dest_acc,
00235                                             f);
00236                 }
00237             } // omp parallel
00238         }
00239 
00240 
00241 #else
00242 
00243 
00244         template <class SrcImageIterator1, class SrcAccessor1,
00245                   class SrcImageIterator2, class SrcAccessor2,
00246                   class DestImageIterator, class DestAccessor,
00247                   class Functor>
00248         inline void
00249         combineTwoImages(SrcImageIterator1 src1_upperleft,
00250                          SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
00251                          SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
00252                          DestImageIterator dest_upperleft, DestAccessor dest_acc,
00253                          const Functor& func)
00254         {
00255             vigra::combineTwoImages(src1_upperleft, src1_lowerright, src1_acc,
00256                                     src2_upperleft, src2_acc,
00257                                     dest_upperleft, dest_acc,
00258                                     func);
00259         }
00260 
00261 
00262         template <class SrcImageIterator1, class SrcAccessor1,
00263                   class SrcImageIterator2, class SrcAccessor2,
00264                   class MaskImageIterator, class MaskAccessor,
00265                   class DestImageIterator, class DestAccessor,
00266                   class Functor>
00267         inline void
00268         combineTwoImagesIf(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
00269                            SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
00270                            MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
00271                            DestImageIterator dest_upperleft, DestAccessor dest_acc,
00272                            const Functor& func)
00273         {
00274             vigra::combineTwoImagesIf(src1_upperleft, src1_lowerright, src1_acc,
00275                                       src2_upperleft, src2_acc,
00276                                       mask_upperleft, mask_acc,
00277                                       dest_upperleft, dest_acc,
00278                                       func);
00279         }
00280 
00281 
00282         template <class SrcImageIterator1, class SrcAccessor1,
00283                   class SrcImageIterator2, class SrcAccessor2,
00284                   class SrcImageIterator3, class SrcAccessor3,
00285                   class DestImageIterator, class DestAccessor,
00286                   class Functor>
00287         inline void
00288         combineThreeImages(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc,
00289                            SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc,
00290                            SrcImageIterator3 src3_upperleft, SrcAccessor3 src3_acc,
00291                            DestImageIterator dest_upperleft, DestAccessor dest_acc,
00292                            const Functor& func)
00293         {
00294             vigra::combineThreeImages(src1_upperleft, src1_lowerright, src1_acc,
00295                                       src2_upperleft, src2_acc,
00296                                       src3_upperleft, src3_acc,
00297                                       dest_upperleft, dest_acc,
00298                                       func);
00299         }
00300 
00301 
00302         template <class SrcImageIterator, class SrcAccessor,
00303                   class DestImageIterator, class DestAccessor>
00304         inline void
00305         copyImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
00306                   DestImageIterator dest_upperleft, DestAccessor dest_acc)
00307         {
00308             vigra::copyImage(src_upperleft, src_lowerright, src_acc, dest_upperleft, dest_acc);
00309         }
00310 
00311 
00312         template <class SrcImageIterator, class SrcAccessor,
00313                   class MaskImageIterator, class MaskAccessor,
00314                   class DestImageIterator, class DestAccessor>
00315         inline void
00316         copyImageIf(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
00317                     MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
00318                     DestImageIterator dest_upperleft, DestAccessor dest_acc)
00319         {
00320             vigra::copyImageIf(src_upperleft, src_lowerright, src_acc,
00321                                mask_upperleft, mask_acc,
00322                                dest_upperleft, dest_acc);
00323         }
00324 
00325 
00326         template <class SrcImageIterator, class SrcAccessor,
00327                   class DestImageIterator, class DestAccessor,
00328                   class Functor>
00329         inline void
00330         transformImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
00331                        DestImageIterator dest_upperleft, DestAccessor dest_acc,
00332                        const Functor& func)
00333         {
00334             vigra::transformImage(src_upperleft, src_lowerright, src_acc,
00335                                   dest_upperleft, dest_acc,
00336                                   func);
00337         }
00338 
00339 
00340         template <class SrcImageIterator, class SrcAccessor,
00341                   class MaskImageIterator, class MaskAccessor,
00342                   class DestImageIterator, class DestAccessor,
00343                   class Functor>
00344         inline void
00345         transformImageIf(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc,
00346                          MaskImageIterator mask_upperleft, MaskAccessor mask_acc,
00347                          DestImageIterator dest_upperleft, DestAccessor dest_acc,
00348                          const Functor& func)
00349         {
00350             vigra::transformImageIf(src_upperleft, src_lowerright, src_acc,
00351                                     mask_upperleft, mask_acc,
00352                                     dest_upperleft, dest_acc,
00353                                     func);
00354         }
00355 
00356 #endif // OPENMP
00357 
00358 
00359         //
00360         // Argument Object Factory versions
00361         //
00362 
00363         template <class SrcImageIterator1, class SrcAccessor1,
00364                   class SrcImageIterator2, class SrcAccessor2,
00365                   class DestImageIterator, class DestAccessor,
00366                   class Functor>
00367         inline void
00368         combineTwoImages(vigra::triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
00369                          vigra::pair<SrcImageIterator2, SrcAccessor2> src2,
00370                          vigra::pair<DestImageIterator, DestAccessor> dest,
00371                          const Functor& functor)
00372         {
00373             vigra::omp::combineTwoImages(src1.first, src1.second, src1.third,
00374                                          src2.first, src2.second,
00375                                          dest.first, dest.second,
00376                                          functor);
00377         }
00378 
00379 
00380         template <class SrcImageIterator1, class SrcAccessor1,
00381                   class SrcImageIterator2, class SrcAccessor2,
00382                   class MaskImageIterator, class MaskAccessor,
00383                   class DestImageIterator, class DestAccessor,
00384                   class Functor>
00385         inline void
00386         combineTwoImagesIf(vigra::triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
00387                            vigra::pair<SrcImageIterator2, SrcAccessor2> src2,
00388                            vigra::pair<MaskImageIterator, MaskAccessor> mask,
00389                            vigra::pair<DestImageIterator, DestAccessor> dest,
00390                            const Functor& functor)
00391         {
00392             vigra::omp::combineTwoImagesIf(src1.first, src1.second, src1.third,
00393                                            src2.first, src2.second,
00394                                            mask.first, mask.second,
00395                                            dest.first, dest.second,
00396                                            functor);
00397         }
00398 
00399 
00400         template <class SrcImageIterator1, class SrcAccessor1,
00401                   class SrcImageIterator2, class SrcAccessor2,
00402                   class SrcImageIterator3, class SrcAccessor3,
00403                   class DestImageIterator, class DestAccessor,
00404                   class Functor>
00405         inline void
00406         combineThreeImages(vigra::triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
00407                            vigra::pair<SrcImageIterator2, SrcAccessor2> src2,
00408                            vigra::pair<SrcImageIterator3, SrcAccessor3> src3,
00409                            vigra::pair<DestImageIterator, DestAccessor> dest,
00410                            const Functor& functor)
00411         {
00412             vigra::omp::combineThreeImages(src1.first, src1.second, src1.third,
00413                                            src2.first, src2.second,
00414                                            src3.first, src3.second,
00415                                            dest.first, dest.second,
00416                                            functor);
00417         }
00418 
00419 
00420         template <class SrcImageIterator, class SrcAccessor,
00421                   class DestImageIterator, class DestAccessor,
00422                   class Functor>
00423         inline void
00424         transformImage(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
00425                        vigra::pair<DestImageIterator, DestAccessor> dest,
00426                        const Functor& functor)
00427         {
00428             vigra::omp::transformImage(src.first, src.second, src.third,
00429                                        dest.first, dest.second,
00430                                        functor);
00431         }
00432 
00433 
00434         template <class SrcImageIterator, class SrcAccessor,
00435                   class DestImageIterator, class DestAccessor>
00436         inline void
00437         copyImage(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
00438                   vigra::pair<DestImageIterator, DestAccessor> dest)
00439         {
00440             vigra::omp::copyImage(src.first, src.second, src.third,
00441                                   dest.first, dest.second);
00442         }
00443 
00444 
00445         template <class SrcImageIterator, class SrcAccessor,
00446                   class MaskImageIterator, class MaskAccessor,
00447                   class DestImageIterator, class DestAccessor>
00448         inline void
00449         copyImageIf(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
00450                     vigra::pair<MaskImageIterator, MaskAccessor> mask,
00451                     vigra::pair<DestImageIterator, DestAccessor> dest)
00452         {
00453             vigra::omp::copyImageIf(src.first, src.second, src.third,
00454                                     mask.first, mask.second,
00455                                     dest.first, dest.second);
00456         }
00457 
00458 
00459         template <class SrcImageIterator, class SrcAccessor,
00460                   class MaskImageIterator, class MaskAccessor,
00461                   class DestImageIterator, class DestAccessor,
00462                   class Functor>
00463         inline void
00464         transformImageIf(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
00465                          vigra::pair<MaskImageIterator, MaskAccessor> mask,
00466                          vigra::pair<DestImageIterator, DestAccessor> dest,
00467                          const Functor& functor)
00468         {
00469             vigra::omp::transformImageIf(src.first, src.second, src.third,
00470                                          mask.first, mask.second,
00471                                          dest.first, dest.second,
00472                                          functor);
00473         }
00474 
00475     } // namespace omp
00476 } // namespace vigra
00477 
00478 
00479 #endif // OPENMP_VIGRA_H_INCLUDED_
00480 
00481 // Local Variables:
00482 // mode: c++
00483 // End:

Generated on 20 Apr 2018 for Hugintrunk by  doxygen 1.4.7