Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 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; // No-op. 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 } // end of namespace mln::border::impl 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 // No-op. 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 // Effective resizing. 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 } // end of namespace mln::border::internal 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 // Try to resize the primary image behind ima. 00133 internal::resize_dispatch(primary(ima), thickness); 00134 00135 trace::exiting("border::resize"); 00136 } 00137 00138 # endif // ! MLN_INCLUDE_ONLY 00139 00140 } // end of namespace mln::border 00141 00142 } // end of namespace mln 00143 00144 00145 #endif // ! MLN_BORDER_RESIZE_HH