VIGRA - vigra/copyimage.hxx Source File

[ VIGRA Homepage | Class Index | Function Index | File Index | 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.5.0, Dec 07 2006 )                                    */
    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 /*        koethe@informatik.uni-hamburg.de          or                  */
    00012 /*        vigra@kogs1.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 template <class SrcImageIterator, class SrcAccessor,
    00146           class DestImageIterator, class DestAccessor>
    00147 void
    00148 copyImage(SrcImageIterator src_upperleft,
    00149           SrcImageIterator src_lowerright, SrcAccessor sa,
    00150           DestImageIterator dest_upperleft, DestAccessor da)
    00151 {
    00152     int w = src_lowerright.x - src_upperleft.x;
    00153
    00154     for(; src_upperleft.y<src_lowerright.y; ++src_upperleft.y, ++dest_upperleft.y)
    00155     {
    00156         copyLine(src_upperleft.rowIterator(),
    00157                  src_upperleft.rowIterator() + w, sa,
    00158                  dest_upperleft.rowIterator(), da);
    00159     }
    00160 }
    00161
    00162 template <class SrcImageIterator, class SrcAccessor,
    00163           class DestImageIterator, class DestAccessor>
    00164 inline
    00165 void
    00166 copyImage(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00167       pair<DestImageIterator, DestAccessor> dest)
    00168 {
    00169     copyImage(src.first, src.second, src.third,
    00170                    dest.first, dest.second);
    00171 }
    00172
    00173 /********************************************************/
    00174 /*                                                      */
    00175 /*                       copyImageIf                    */
    00176 /*                                                      */
    00177 /********************************************************/
    00178
    00179 /** \brief Copy source ROI into destination image.
    00180
    00181     Pixel values are copied whenever the return value of the mask's
    00182     accessor is not zero.
    00183     If necessary, type conversion takes place.
    00184     The function uses accessors to access the pixel data.
    00185
    00186     <b> Declarations:</b>
    00187
    00188     pass arguments explicitly:
    00189     \code
    00190     namespace vigra {
    00191         template <class SrcImageIterator, class SrcAccessor,
    00192               class MaskImageIterator, class MaskAccessor,
    00193               class DestImageIterator, clas DestAccessor>
    00194         void
    00195         copyImageIf(SrcImageIterator src_upperleft,
    00196             SrcImageIterator src_lowerright, SrcAccessor sa,
    00197             MaskImageIterator mask_upperleft, MaskAccessor ma,
    00198             DestImageIterator dest_upperleft, DestAccessor da)
    00199     }
    00200     \endcode
    00201
    00202
    00203     use argument objects in conjunction with \ref ArgumentObjectFactories:
    00204     \code
    00205     namespace vigra {
    00206         template <class SrcImageIterator, class SrcAccessor,
    00207               class MaskImageIterator, class MaskAccessor,
    00208               class DestImageIterator, clas DestAccessor>
    00209         void
    00210         copyImageIf(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00211             pair<MaskImageIterator, MaskAccessor> mask,
    00212             pair<DestImageIterator, DestAccessor> dest)
    00213     }
    00214     \endcode
    00215
    00216     <b> Usage:</b>
    00217
    00218         <b>\#include</b> "<a href="copyimage_8hxx-source.html">vigra/copyimage.hxx</a>"<br>
    00219         Namespace: vigra
    00220
    00221     \code
    00222     vigra::copyImageIf(srcImageRange(src), maskImage(mask), destImage(dest));
    00223
    00224     \endcode
    00225
    00226     <b> Required Interface:</b>
    00227
    00228     \code
    00229     SrcImageIterator src_upperleft, src_lowerright;
    00230     DestImageIterator dest_upperleft;
    00231     MaskImageIterator mask_upperleft;
    00232     SrcImageIterator::row_iterator sx = src_upperleft.rowIterator();
    00233     MaskImageIterator::row_iterator mx = mask_upperleft.rowIterator();
    00234     DestImageIterator::row_iterator dx = dest_upperleft.rowIterator();
    00235
    00236     SrcAccessor src_accessor;
    00237     DestAccessor dest_accessor;
    00238     MaskAccessor mask_accessor;
    00239     Functor functor;
    00240
    00241     if(mask_accessor(mx))
    00242         dest_accessor.set(src_accessor(sx), dx);
    00243
    00244     \endcode
    00245
    00246 */
    00247 template <class SrcImageIterator, class SrcAccessor,
    00248           class MaskImageIterator, class MaskAccessor,
    00249           class DestImageIterator, class DestAccessor>
    00250 void
    00251 copyImageIf(SrcImageIterator src_upperleft,
    00252             SrcImageIterator src_lowerright, SrcAccessor sa,
    00253             MaskImageIterator mask_upperleft, MaskAccessor ma,
    00254         DestImageIterator dest_upperleft, DestAccessor da)
    00255 {
    00256     int w = src_lowerright.x - src_upperleft.x;
    00257
    00258     for(; src_upperleft.y<src_lowerright.y;
    00259              ++src_upperleft.y, ++mask_upperleft.y, ++dest_upperleft.y)
    00260     {
    00261         copyLineIf(src_upperleft.rowIterator(),
    00262                    src_upperleft.rowIterator() + w, sa,
    00263                    mask_upperleft.rowIterator(), ma,
    00264                    dest_upperleft.rowIterator(), da);
    00265     }
    00266 }
    00267
    00268 template <class SrcImageIterator, class SrcAccessor,
    00269           class MaskImageIterator, class MaskAccessor,
    00270           class DestImageIterator, class DestAccessor>
    00271 inline
    00272 void
    00273 copyImageIf(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00274         pair<MaskImageIterator, MaskAccessor> mask,
    00275         pair<DestImageIterator, DestAccessor> dest)
    00276 {
    00277     copyImageIf(src.first, src.second, src.third,
    00278                 mask.first, mask.second,
    00279         dest.first, dest.second);
    00280 }
    00281
    00282 //@}
    00283
    00284 } // namespace vigra
    00285
    00286 #endif // VIGRA_COPYIMAGE_HXX

© Ullrich Köthe (koethe@informatik.uni-hamburg.de) Cognitive Systems Group, University of Hamburg, Germany | html generated using doxygen and Python VIGRA 1.5.0 (7 Dec 2006)