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_CORE_CONCEPT_NEIGHBORHOOD_HH 00027 # define MLN_CORE_CONCEPT_NEIGHBORHOOD_HH 00028 00032 00033 # include <mln/core/concept/window.hh> 00034 # include <mln/trait/windows.hh> 00035 00036 00037 00038 # define mln_is_simple_neighborhood(N) mln_is_simple_window(mln_window(N)) 00039 00040 00041 00042 00043 namespace mln 00044 { 00045 00046 00047 // Forward declaration. 00048 template <typename E> struct Neighborhood; 00049 00050 00052 00053 template <> 00054 struct Neighborhood<void> 00055 { 00056 typedef Object<void> super; 00057 }; 00058 00059 00064 00065 template <typename E> 00066 struct Neighborhood : public Object<E> 00067 { 00068 typedef Neighborhood<void> category; 00069 00070 /* 00071 typedef niter; 00072 typedef fwd_niter; 00073 typedef bkd_niter; 00074 00075 typedef window; 00076 either 00077 const window& win() const; 00078 or 00079 window win() const; 00080 */ 00081 00082 protected: 00083 Neighborhood(); 00084 }; 00085 00086 00087 00088 template <typename L, typename R> 00089 bool operator==(const Neighborhood<L>& lhs, const Neighborhood<R>& rhs); 00090 00091 00092 template <typename N> 00093 std::ostream& 00094 operator<<(std::ostream&ostr, const Neighborhood<N>& nbh); 00095 00096 00097 // FIXME: Move as a method of Image? 00098 template <typename I, typename N> 00099 util::array<int> 00100 offsets_wrt(const Image<I>& ima, const Neighborhood<N>& nbh); 00101 00102 template <typename I, typename N> 00103 util::array<int> 00104 positive_offsets_wrt(const Image<I>& ima, const Neighborhood<N>& nbh); 00105 00106 template <typename I, typename N> 00107 util::array<int> 00108 negative_offsets_wrt(const Image<I>& ima, const Neighborhood<N>& nbh); 00109 00110 00111 00112 # ifndef MLN_INCLUDE_ONLY 00113 00114 template <typename E> 00115 inline 00116 Neighborhood<E>::Neighborhood() 00117 { 00118 typedef mln_niter(E) niter; 00119 typedef mln_fwd_niter(E) fwd_niter; 00120 typedef mln_bkd_niter(E) bkd_niter; 00121 00122 typedef mln_window(E) window; 00123 bool m = (& E::win) == (& E::win); 00124 m = 0; 00125 bool (E::*m2)() const = &E::is_valid; 00126 m2 = 0; 00127 00128 # if 0 00129 /* FIXME: Disabled, as win() can either return a const reference 00130 or a copy of the window (see documentation above). Hence the 00131 simpler, relaxed check above (m0). */ 00132 const window& (E::*m1)() const = & E::win; 00133 m = m1; 00134 # endif 00135 } 00136 00137 00138 template <typename L, typename R> 00139 inline 00140 bool operator==(const Neighborhood<L>& lhs, const Neighborhood<R>& rhs) 00141 { 00142 return exact(lhs).win() == exact(rhs).win(); 00143 } 00144 00145 template <typename N> 00146 inline 00147 std::ostream& 00148 operator<<(std::ostream&ostr, const Neighborhood<N>& nbh) 00149 { 00150 return ostr << exact(nbh).win(); 00151 } 00152 00153 template <typename I, typename N> 00154 inline 00155 util::array<int> 00156 offsets_wrt(const Image<I>& ima_, const Neighborhood<N>& nbh_) 00157 { 00158 mln_is_simple_neighborhood(N)::check(); 00159 00160 const I& ima = exact(ima_); 00161 const N& nbh = exact(nbh_); 00162 mln_precondition(ima.is_valid()); 00163 mln_precondition(nbh.is_valid()); 00164 00165 return offsets_wrt(ima, nbh.win()); 00166 } 00167 00168 template <typename I, typename N> 00169 util::array<int> 00170 positive_offsets_wrt(const Image<I>& ima_, const Neighborhood<N>& nbh_) 00171 { 00172 mln_is_simple_neighborhood(N)::check(); 00173 00174 const I& ima = exact(ima_); 00175 const N& nbh = exact(nbh_); 00176 mln_precondition(ima.is_valid()); 00177 mln_precondition(nbh.is_valid()); 00178 00179 return positive_offsets_wrt(ima, nbh.win()); 00180 } 00181 00182 template <typename I, typename N> 00183 util::array<int> 00184 negative_offsets_wrt(const Image<I>& ima_, const Neighborhood<N>& nbh_) 00185 { 00186 mln_is_simple_neighborhood(N)::check(); 00187 00188 const I& ima = exact(ima_); 00189 const N& nbh = exact(nbh_); 00190 mln_precondition(ima.is_valid()); 00191 mln_precondition(nbh.is_valid()); 00192 00193 return negative_offsets_wrt(ima, nbh.win()); 00194 } 00195 00196 # endif // ! MLN_INCLUDE_ONLY 00197 00198 } // end of namespace mln 00199 00200 00201 #endif // ! MLN_CORE_CONCEPT_NEIGHBORHOOD_HH