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_CORE_ALIAS_NEIGHB3D_HH
00027 # define MLN_CORE_ALIAS_NEIGHB3D_HH
00028
00033
00034
00035 # include <cmath>
00036 # include <mln/core/neighb.hh>
00037 # include <mln/core/alias/window3d.hh>
00038 # include <mln/win/sym.hh>
00039 # include <mln/convert/from_to.hh>
00040
00041
00042 namespace mln
00043 {
00044
00049
00050 typedef neighb<window3d> neighb3d;
00051
00053
00075 const neighb3d& c4_3d();
00076
00078
00100 const neighb3d& c8_3d();
00101
00102
00104
00126 const neighb3d& c6();
00127
00129
00151 const neighb3d& c18();
00152
00154
00176 const neighb3d& c26();
00177
00178
00179
00180
00181 namespace convert
00182 {
00183
00184 namespace over_load
00185 {
00186
00187 template <unsigned S>
00188 void from_to_(const bool (&values)[S], neighb3d& nbh);
00189
00190 }
00191
00192 }
00193
00194
00195
00196 # ifndef MLN_INCLUDE_ONLY
00197
00198 inline
00199 const neighb3d& c4_3d()
00200 {
00201 static neighb3d it;
00202 if (it.size() == 0)
00203 {
00204 window3d& win = it.hook_win_();
00205 win
00206 .insert(0, 1, 0)
00207 .insert(0, 0, 1);
00208 win
00209 .insert(win::sym(win));
00210 }
00211 return it;
00212 }
00213
00214 inline
00215 const neighb3d& c8_3d()
00216 {
00217 static neighb3d it;
00218 if (it.size() == 0)
00219 {
00220 static const bool vals[] = { 1, 1, 1,
00221 1, 0, 1,
00222 1, 1, 1 };
00223 convert::from_to(vals, it);
00224 }
00225 return it;
00226 }
00227
00228 inline
00229 const neighb3d& c6()
00230 {
00231 static neighb3d it;
00232 if (it.size() == 0)
00233 {
00234 window3d& win = it.hook_win_();
00235 win
00236 .insert(1, 0, 0)
00237 .insert(0, 1, 0)
00238 .insert(0, 0, 1);
00239 win
00240 .insert(win::sym(win));
00241 }
00242 return it;
00243 }
00244
00245 inline
00246 const neighb3d& c18()
00247 {
00248 static neighb3d it;
00249 if (it.size() == 0)
00250 {
00251 window3d& win = it.hook_win_();
00252 win
00253 .insert(1, 0, 1)
00254 .insert(1, 0, -1)
00255 .insert(0, 1, 1)
00256 .insert(0, 1, -1)
00257 .insert(1, 1, 0)
00258 .insert(1, -1, 0);
00259 win
00260 .insert(win::sym(win))
00261 .insert(c6().win());
00262 }
00263 return it;
00264 }
00265
00266 inline
00267 const neighb3d& c26()
00268 {
00269 static neighb3d it;
00270 if (it.size() == 0)
00271 {
00272 window3d& win = it.hook_win_();
00273 win
00274 .insert(1, 1, 1)
00275 .insert(1, 1, -1)
00276 .insert(1, -1, 1)
00277 .insert(1, -1, -1);
00278 win
00279 .insert(win::sym(win))
00280 .insert(c18().win());
00281 }
00282 return it;
00283 }
00284
00285
00286 namespace convert
00287 {
00288
00289 namespace over_load
00290 {
00291
00292 template <unsigned S>
00293 void
00294 from_to_(const bool (&values)[S], neighb3d& nbh)
00295 {
00296 # ifndef NDEBUG
00297 const int h = unsigned(std::pow(float(S), float(1. / 3.))) / 2;
00298 mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == S);
00299 # endif // ! NDEBUG
00300 window3d win;
00301 from_to_(values, win);
00302 mln_precondition(win.is_neighbable_());
00303 nbh.change_window(win);
00304 }
00305
00306 }
00307
00308 }
00309
00310 # endif // ! MLN_INCLUDE_ONLY
00311
00312 }
00313
00314
00315 #endif // ! MLN_CORE_ALIAS_NEIGHB3D_HH