[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

vigra/copyimage.hxx |

    00001 /************************************************************************/
    00002 /*                                                                      */
    00003 /*               Copyright 1998-2002 by Ullrich Koethe                  */
    00004 /*                                                                      */
    00005 /*    This file is part of the VIGRA computer vision library.           */
    00006 /*    The VIGRA Website is                                              */
    00007 /*        http://hci.iwr.uni-heidelberg.de/vigra/                       */
    00008 /*    Please direct questions, bug reports, and contributions to        */
    00009 /*        ullrich.koethe@iwr.uni-heidelberg.de    or                    */
    00010 /*        vigra@informatik.uni-hamburg.de                               */
    00011 /*                                                                      */
    00012 /*    Permission is hereby granted, free of charge, to any person       */
    00013 /*    obtaining a copy of this software and associated documentation    */
    00014 /*    files (the "Software"), to deal in the Software without           */
    00015 /*    restriction, including without limitation the rights to use,      */
    00016 /*    copy, modify, merge, publish, distribute, sublicense, and/or      */
    00017 /*    sell copies of the Software, and to permit persons to whom the    */
    00018 /*    Software is furnished to do so, subject to the following          */
    00019 /*    conditions:                                                       */
    00020 /*                                                                      */
    00021 /*    The above copyright notice and this permission notice shall be    */
    00022 /*    included in all copies or substantial portions of the             */
    00023 /*    Software.                                                         */
    00024 /*                                                                      */
    00025 /*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
    00026 /*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
    00027 /*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
    00028 /*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
    00029 /*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
    00030 /*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
    00031 /*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
    00032 /*    OTHER DEALINGS IN THE SOFTWARE.                                   */
    00033 /*                                                                      */
    00034 /************************************************************************/
    00035
    00036
    00037 #ifndef VIGRA_COPYIMAGE_HXX
    00038 #define VIGRA_COPYIMAGE_HXX
    00039
    00040 #include "utilities.hxx"
    00041
    00042 namespace vigra {
    00043
    00044 /** \addtogroup CopyAlgo Algorithms to Copy Images
    00045     Copy images or regions
    00046 */
    00047 //@{
    00048
    00049 /********************************************************/
    00050 /*                                                      */
    00051 /*                       copyLine                       */
    00052 /*                                                      */
    00053 /********************************************************/
    00054
    00055 template <class SrcIterator, class SrcAccessor,
    00056           class DestIterator, class DestAccessor>
    00057 void
    00058 copyLine(SrcIterator s,
    00059          SrcIterator send, SrcAccessor src,
    00060          DestIterator d, DestAccessor dest)
    00061 {
    00062     for(; s != send; ++s, ++d)
    00063         dest.set(src(s), d);
    00064 }
    00065
    00066 template <class SrcIterator, class SrcAccessor,
    00067           class MaskIterator, class MaskAccessor,
    00068           class DestIterator, class DestAccessor>
    00069 void
    00070 copyLineIf(SrcIterator s,
    00071            SrcIterator send, SrcAccessor src,
    00072            MaskIterator m, MaskAccessor mask,
    00073            DestIterator d, DestAccessor dest)
    00074 {
    00075     for(; s != send; ++s, ++d, ++m)
    00076         if(mask(m))
    00077             dest.set(src(s), d);
    00078 }
    00079
    00080 template <class SrcIterator, class SrcAccessor,
    00081           class DestIterator, class DestAccessor>
    00082 void
    00083 swapLine(SrcIterator s,
    00084          SrcIterator send, SrcAccessor src,
    00085          DestIterator d, DestAccessor dest)
    00086 {
    00087     for(; s != send; ++s, ++d)
    00088     {
    00089         typename SrcAccessor::value_type t = src(s);
    00090         src.set(dest(d), s);
    00091         dest.set(t, d);
    00092     }
    00093 }
    00094
    00095 /********************************************************/
    00096 /*                                                      */
    00097 /*                        copyImage                     */
    00098 /*                                                      */
    00099 /********************************************************/
    00100
    00101 /** \brief Copy source image into destination image.
    00102
    00103     If necessary, type conversion takes place.
    00104     The function uses accessors to access the pixel data.
    00105
    00106     <b> Declarations:</b>
    00107
    00108     pass arguments explicitly:
    00109     \code
    00110     namespace vigra {
    00111         template <class SrcImageIterator, class SrcAccessor,
    00112               class DestImageIterator, class DestAccessor>
    00113         void
    00114         copyImage(SrcImageIterator src_upperleft,
    00115               SrcImageIterator src_lowerright, SrcAccessor sa,
    00116               DestImageIterator dest_upperleft, DestAccessor da)
    00117     }
    00118     \endcode
    00119
    00120
    00121     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00122     \code
    00123     namespace vigra {
    00124         template <class SrcImageIterator, class SrcAccessor,
    00125               class DestImageIterator, class DestAccessor>
    00126         void
    00127         copyImage(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00128               pair<DestImageIterator, DestAccessor> dest)
    00129     }
    00130     \endcode
    00131
    00132     <b> Usage:</b>
    00133
    00134         <b>\#include</b> <<a href="copyimage_8hxx-source.html">vigra/copyimage.hxx</a>><br>
    00135         Namespace: vigra
    00136
    00137     \code
    00138     vigra::copyImage(srcImageRange(src), destImage(dest));
    00139
    00140     \endcode
    00141
    00142     <b> Required Interface:</b>
    00143
    00144     \code
    00145     SrcImageIterator src_upperleft, src_lowerright;
    00146     DestImageIterator      dest_upperleft;
    00147     SrcImageIterator::row_iterator sx = src_upperleft.rowIterator();
    00148     DestImageIterator::row_iterator dx = dest_upperleft.rowIterator();
    00149
    00150     SrcAccessor src_accessor;
    00151     DestAccessor dest_accessor;
    00152
    00153     dest_accessor.set(src_accessor(sx), dx);
    00154
    00155     \endcode
    00156
    00157 */
    00158 doxygen_overloaded_function(template <...> void copyImage)
    00159
    00160 template <class SrcImageIterator, class SrcAccessor,
    00161           class DestImageIterator, class DestAccessor>
    00162 void
    00163 copyImage(SrcImageIterator src_upperleft,
    00164           SrcImageIterator src_lowerright, SrcAccessor sa,
    00165           DestImageIterator dest_upperleft, DestAccessor da)
    00166 {
    00167     int w = src_lowerright.x - src_upperleft.x;
    00168
    00169     for(; src_upperleft.y<src_lowerright.y; ++src_upperleft.y, ++dest_upperleft.y)
    00170     {
    00171         copyLine(src_upperleft.rowIterator(),
    00172                  src_upperleft.rowIterator() + w, sa,
    00173                  dest_upperleft.rowIterator(), da);
    00174     }
    00175 }
    00176
    00177 template <class SrcImageIterator, class SrcAccessor,
    00178           class DestImageIterator, class DestAccessor>
    00179 inline
    00180 void
    00181 copyImage(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00182       pair<DestImageIterator, DestAccessor> dest)
    00183 {
    00184     copyImage(src.first, src.second, src.third,
    00185                    dest.first, dest.second);
    00186 }
    00187
    00188 template <class SrcImageIterator, class SrcAccessor,
    00189           class DestImageIterator, class DestAccessor>
    00190 void
    00191 swapImageData(SrcImageIterator src_upperleft,
    00192               SrcImageIterator src_lowerright, SrcAccessor sa,
    00193               DestImageIterator dest_upperleft, DestAccessor da)
    00194 {
    00195     int w = src_lowerright.x - src_upperleft.x;
    00196
    00197     for(; src_upperleft.y<src_lowerright.y; ++src_upperleft.y, ++dest_upperleft.y)
    00198     {
    00199         swapLine(src_upperleft.rowIterator(),
    00200                  src_upperleft.rowIterator() + w, sa,
    00201                  dest_upperleft.rowIterator(), da);
    00202     }
    00203 }
    00204
    00205 template <class SrcImageIterator, class SrcAccessor,
    00206           class DestImageIterator, class DestAccessor>
    00207 inline
    00208 void
    00209 swapImageData(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00210               pair<DestImageIterator, DestAccessor> dest)
    00211 {
    00212     swapImageData(src.first, src.second, src.third,
    00213                   dest.first, dest.second);
    00214 }
    00215
    00216 /********************************************************/
    00217 /*                                                      */
    00218 /*                       copyImageIf                    */
    00219 /*                                                      */
    00220 /********************************************************/
    00221
    00222 /** \brief Copy source ROI into destination image.
    00223
    00224     Pixel values are copied whenever the return value of the mask's
    00225     accessor is not zero.
    00226     If necessary, type conversion takes place.
    00227     The function uses accessors to access the pixel data.
    00228
    00229     <b> Declarations:</b>
    00230
    00231     pass arguments explicitly:
    00232     \code
    00233     namespace vigra {
    00234         template <class SrcImageIterator, class SrcAccessor,
    00235               class MaskImageIterator, class MaskAccessor,
    00236               class DestImageIterator, clas DestAccessor>
    00237         void
    00238         copyImageIf(SrcImageIterator src_upperleft,
    00239             SrcImageIterator src_lowerright, SrcAccessor sa,
    00240             MaskImageIterator mask_upperleft, MaskAccessor ma,
    00241             DestImageIterator dest_upperleft, DestAccessor da)
    00242     }
    00243     \endcode
    00244
    00245
    00246     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00247     \code
    00248     namespace vigra {
    00249         template <class SrcImageIterator, class SrcAccessor,
    00250               class MaskImageIterator, class MaskAccessor,
    00251               class DestImageIterator, clas DestAccessor>
    00252         void
    00253         copyImageIf(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00254             pair<MaskImageIterator, MaskAccessor> mask,
    00255             pair<DestImageIterator, DestAccessor> dest)
    00256     }
    00257     \endcode
    00258
    00259     <b> Usage:</b>
    00260
    00261         <b>\#include</b> <<a href="copyimage_8hxx-source.html">vigra/copyimage.hxx</a>><br>
    00262         Namespace: vigra
    00263
    00264     \code
    00265     vigra::copyImageIf(srcImageRange(src), maskImage(mask), destImage(dest));
    00266
    00267     \endcode
    00268
    00269     <b> Required Interface:</b>
    00270
    00271     \code
    00272     SrcImageIterator src_upperleft, src_lowerright;
    00273     DestImageIterator dest_upperleft;
    00274     MaskImageIterator mask_upperleft;
    00275     SrcImageIterator::row_iterator sx = src_upperleft.rowIterator();
    00276     MaskImageIterator::row_iterator mx = mask_upperleft.rowIterator();
    00277     DestImageIterator::row_iterator dx = dest_upperleft.rowIterator();
    00278
    00279     SrcAccessor src_accessor;
    00280     DestAccessor dest_accessor;
    00281     MaskAccessor mask_accessor;
    00282     Functor functor;
    00283
    00284     if(mask_accessor(mx))
    00285         dest_accessor.set(src_accessor(sx), dx);
    00286
    00287     \endcode
    00288
    00289 */
    00290 doxygen_overloaded_function(template <...> void copyImageIf)
    00291
    00292 template <class SrcImageIterator, class SrcAccessor,
    00293           class MaskImageIterator, class MaskAccessor,
    00294           class DestImageIterator, class DestAccessor>
    00295 void
    00296 copyImageIf(SrcImageIterator src_upperleft,
    00297             SrcImageIterator src_lowerright, SrcAccessor sa,
    00298             MaskImageIterator mask_upperleft, MaskAccessor ma,
    00299         DestImageIterator dest_upperleft, DestAccessor da)
    00300 {
    00301     int w = src_lowerright.x - src_upperleft.x;
    00302
    00303     for(; src_upperleft.y<src_lowerright.y;
    00304              ++src_upperleft.y, ++mask_upperleft.y, ++dest_upperleft.y)
    00305     {
    00306         copyLineIf(src_upperleft.rowIterator(),
    00307                    src_upperleft.rowIterator() + w, sa,
    00308                    mask_upperleft.rowIterator(), ma,
    00309                    dest_upperleft.rowIterator(), da);
    00310     }
    00311 }
    00312
    00313 template <class SrcImageIterator, class SrcAccessor,
    00314           class MaskImageIterator, class MaskAccessor,
    00315           class DestImageIterator, class DestAccessor>
    00316 inline
    00317 void
    00318 copyImageIf(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00319         pair<MaskImageIterator, MaskAccessor> mask,
    00320         pair<DestImageIterator, DestAccessor> dest)
    00321 {
    00322     copyImageIf(src.first, src.second, src.third,
    00323                 mask.first, mask.second,
    00324         dest.first, dest.second);
    00325 }
    00326
    00327 //@}
    00328
    00329 } // namespace vigra
    00330
    00331 #endif // VIGRA_COPYIMAGE_HXX

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.7.1 (3 Dec 2010)