00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_BORDER_RESIZE_HH
00027 # define MLN_BORDER_RESIZE_HH
00028 
00037 
00038 # include <mln/core/concept/image.hh>
00039 # include <mln/core/routine/duplicate.hh>
00040 # include <mln/core/routine/primary.hh>
00041 # include <mln/border/get.hh>
00042 # include <mln/data/fill.hh>
00043 
00044 
00045 namespace mln
00046 {
00047 
00048   namespace border
00049   {
00050 
00062     template <typename I>
00063     void resize(const Image<I>& ima, unsigned thickness);
00064 
00065 
00066 
00067 # ifndef MLN_INCLUDE_ONLY
00068 
00069     namespace impl
00070     {
00071 
00072       template <typename I>
00073       inline
00074       void resize(I& ima, unsigned thickness)
00075       {
00076         if (border::get(ima) == thickness)
00077           return; 
00078 
00079         mln_concrete(I) memo = mln::duplicate(ima);
00080         ima.resize_(thickness);
00081         data::fill(ima, memo);
00082 
00083         mln_postcondition(border::get(ima) == thickness);
00084       }
00085 
00086     } 
00087 
00088 
00089     namespace internal
00090     {
00091 
00092       template <typename I>
00093       inline
00094       void resize_dispatch(trait::image::ext_domain::any,
00095                            const Image<I>& ima, unsigned thickness)
00096       {
00097         
00098         (void) ima;
00099         (void) thickness;
00100       }
00101 
00102       template <typename I>
00103       inline
00104       void resize_dispatch(trait::image::ext_domain::extendable,
00105                            const Image<I>& ima, unsigned thickness)
00106       {
00107         
00108         impl::resize(const_cast<I&>(exact(ima)), thickness);
00109       }
00110 
00111       template <typename I>
00112       inline
00113       void resize_dispatch(const Image<I>& ima, unsigned thickness)
00114       {
00115         resize_dispatch(mln_trait_image_ext_domain(I)(),
00116                         ima, thickness);
00117       }
00118 
00119     } 
00120 
00121 
00123 
00124     template <typename I>
00125     inline
00126     void resize(const Image<I>& ima, unsigned thickness)
00127     {
00128       trace::entering("border::resize");
00129 
00130       mln_precondition(exact(ima).is_valid());
00131 
00132       
00133       internal::resize_dispatch(primary(ima), thickness);
00134 
00135       trace::exiting("border::resize");
00136     }
00137 
00138 # endif // ! MLN_INCLUDE_ONLY
00139 
00140   } 
00141 
00142 } 
00143 
00144 
00145 #endif // ! MLN_BORDER_RESIZE_HH