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_ALIAS_NEIGHB2D_HH 00027 # define MLN_CORE_ALIAS_NEIGHB2D_HH 00028 00035 00036 # include <cmath> 00037 # include <mln/core/alias/window2d.hh> 00038 # include <mln/core/neighb.hh> 00039 # include <mln/convert/from_to.hh> 00040 # include <mln/make/double_neighb2d.hh> 00041 # include <mln/fun/p2b/chess.hh> 00042 00043 00044 namespace mln 00045 { 00046 00051 typedef neighb<window2d> neighb2d; 00052 00053 } 00054 00055 00056 namespace mln 00057 { 00058 00060 00072 const neighb2d& c4(); 00073 00074 00076 00088 const neighb2d& c8(); 00089 00090 00092 00103 const neighb2d& c2_row(); 00104 00105 00107 00119 const neighb2d& c2_col(); 00120 00121 00122 // FIXME: Documentation 00123 neighb< win::multiple<window2d, mln::fun::p2b::chess> > c6_2d(); 00124 00125 00126 00127 namespace convert 00128 { 00129 00130 namespace over_load 00131 { 00132 00133 template <unsigned S> 00134 void from_to_(const bool (&values)[S], neighb2d& nbh); 00135 00136 template <unsigned R, unsigned C> 00137 void from_to_(bool const (&values)[R][C], neighb2d& nbh); 00138 00139 } // end of namespace mln::convert::over_load 00140 00141 } // end of namespace mln::convert 00142 00143 00144 00145 # ifndef MLN_INCLUDE_ONLY 00146 00147 inline 00148 const neighb2d& c4() 00149 { 00150 static neighb2d it; 00151 if (it.size() == 0) 00152 { 00153 static const bool vals[] = { 0, 1, 0, 00154 1, 0, 1, 00155 0, 1, 0 }; 00156 convert::from_to(vals, it); 00157 } 00158 return it; 00159 } 00160 00161 inline 00162 const neighb2d& c8() 00163 { 00164 static neighb2d it; 00165 if (it.size() == 0) 00166 { 00167 static const bool vals[] = { 1, 1, 1, 00168 1, 0, 1, 00169 1, 1, 1 }; 00170 convert::from_to(vals, it); 00171 } 00172 return it; 00173 } 00174 00175 inline 00176 const neighb2d& c2_row() 00177 { 00178 static neighb2d it; 00179 if (it.size() == 0) 00180 { 00181 static const bool vals[] = { 0, 0, 0, 00182 1, 0, 1, 00183 0, 0, 0 }; 00184 convert::from_to(vals, it); 00185 } 00186 return it; 00187 } 00188 00189 inline 00190 const neighb2d& c2_col() 00191 { 00192 static neighb2d it; 00193 if (it.size() == 0) 00194 { 00195 static const bool vals[] = { 0, 1, 0, 00196 0, 0, 0, 00197 0, 1, 0 }; 00198 convert::from_to(vals, it); 00199 } 00200 return it; 00201 } 00202 00203 00204 inline 00205 neighb< win::multiple<window2d, mln::fun::p2b::chess> > 00206 c6_2d() 00207 { 00208 bool vert[] = { 1, 1, 0, 00209 1, 0, 1, 00210 0, 1, 1 }; 00211 00212 bool hori[] = { 0, 1, 1, 00213 1, 0, 1, 00214 1, 1, 0 }; 00215 00216 return make::double_neighb2d(fun::p2b::chess(), 00217 vert, 00218 hori); 00219 } 00220 00221 00222 namespace convert 00223 { 00224 00225 namespace over_load 00226 { 00227 00228 template <unsigned S> 00229 void 00230 from_to_(const bool (&values)[S], neighb2d& nbh) 00231 { 00232 enum { h = mlc_sqrt_int(S) / 2 }; 00233 mlc_bool((2 * h + 1) * (2 * h + 1) == S)::check(); 00234 window2d& win = nbh.hook_win_(); 00235 convert::from_to(values, win); 00236 mln_postcondition(win.is_neighbable_()); 00237 } 00238 00239 template <unsigned R, unsigned C> 00240 void 00241 from_to_(bool const (&values)[R][C], neighb2d& nbh) 00242 { 00243 mlc_bool(R % 2 == 1)::check(); 00244 mlc_bool(C % 2 == 1)::check(); 00245 window2d& win = nbh.hook_win_(); 00246 convert::from_to(values, win); 00247 mln_postcondition(win.is_neighbable_()); 00248 } 00249 00250 } // end of namespace mln::convert::over_load 00251 00252 } // end of namespace mln::convert 00253 00254 # endif // ! MLN_INCLUDE_ONLY 00255 00256 } // end of namespace mln 00257 00258 00259 00260 #endif // ! MLN_CORE_ALIAS_NEIGHB2D_HH