Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development 00002 // Laboratory (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 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 } // end of namespace mln::convert::over_load 00097 00098 } // end of namespace mln::convert 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 } // end of namespace mln::convert::over_load 00183 00184 } // end of namespace mln::convert 00185 00186 # endif // ! MLN_INCLUDE_ONLY 00187 00188 } // end of namespace mln 00189 00190 00191 #endif // ! MLN_CORE_ALIAS_WINDOW2D_HH