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
00027 #ifndef MLN_CORE_ALIAS_WINDOW2D_HH
00028 # define MLN_CORE_ALIAS_WINDOW2D_HH
00029
00034
00035 # include <mln/core/window.hh>
00036 # include <mln/core/alias/dpoint2d.hh>
00037 # include <mln/metal/math/sqrt.hh>
00038 # include <mln/convert/from_to.hxx>
00039
00040
00041 namespace mln
00042 {
00043
00048
00049 typedef window<mln::dpoint2d> window2d;
00050
00053
00065 const window2d& win_c4p();
00066
00069
00081 const window2d& win_c8p();
00082
00083
00084 namespace convert
00085 {
00086
00087 namespace over_load
00088 {
00089
00090 template <unsigned S>
00091 void from_to_(const bool (&values)[S], window2d& win);
00092
00093 template <unsigned R, unsigned C>
00094 void from_to_(const bool (&values)[R][C], window2d& win);
00095
00096 }
00097
00098 }
00099
00100
00101
00102 # ifndef MLN_INCLUDE_ONLY
00103
00104 inline const window2d&
00105 win_c4p()
00106 {
00107 static window2d it;
00108 if (it.size() == 0)
00109 {
00110 it
00111 .insert( 0, -1)
00112 .insert(-1, 0)
00113 .insert( 0, 0)
00114 .insert(+1, 0)
00115 .insert( 0, +1);
00116 }
00117 return it;
00118 }
00119
00120 inline const window2d&
00121 win_c8p()
00122 {
00123 static window2d it;
00124 if (it.size() == 0)
00125 {
00126 it
00127 .insert(-1, -1)
00128 .insert( 0, -1)
00129 .insert(+1, -1)
00130 .insert(-1, 0)
00131 .insert( 0, 0)
00132 .insert(+1, 0)
00133 .insert(-1, +1)
00134 .insert( 0, +1)
00135 .insert(+1, +1);
00136 }
00137 return it;
00138 }
00139
00140
00141 namespace convert
00142 {
00143
00144 namespace over_load
00145 {
00146
00147 template <unsigned S>
00148 void
00149 from_to_(const bool (&values)[S], window2d& win)
00150 {
00151 enum { H = mlc_sqrt_int(S) / 2 };
00152 mlc_bool((2 * H + 1) * (2 * H + 1) == S)::check();
00153 win.clear();
00154 unsigned i = 0;
00155 const def::coord
00156 h = static_cast<def::coord>(H),
00157 _h = static_cast<def::coord>(-h);
00158 for (def::coord row = _h; row <= h; ++row)
00159 for (def::coord col = _h; col <= h; ++col)
00160 if (values[i++])
00161 win.insert(row, col);
00162 }
00163
00164 template <unsigned R, unsigned C>
00165 void
00166 from_to_(const bool (&values)[R][C], window2d& win)
00167 {
00168 mlc_bool(R % 2 == 1)::check();
00169 mlc_bool(C % 2 == 1)::check();
00170 win.clear();
00171 const def::coord
00172 drow = static_cast<def::coord>(R / 2),
00173 _drow = static_cast<def::coord>(- drow),
00174 dcol = static_cast<def::coord>(C / 2),
00175 _dcol = static_cast<def::coord>(- dcol);
00176 for (def::coord row = _drow; row <= drow; ++row)
00177 for (def::coord col = _dcol; col <= dcol; ++col)
00178 if (values[row + drow][col + dcol])
00179 win.insert(row, col);
00180 }
00181
00182 }
00183
00184 }
00185
00186 # endif // ! MLN_INCLUDE_ONLY
00187
00188 }
00189
00190
00191 #endif // ! MLN_CORE_ALIAS_WINDOW2D_HH