VIGRA - VIGRA: vigra/copyimage.hxx Source File

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

# vigra/copyimage.hxx

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