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_WINDOW3D_HH 00027 # define MLN_CORE_ALIAS_WINDOW3D_HH 00028 00033 00034 # include <cmath> 00035 # include <mln/core/window.hh> 00036 # include <mln/core/alias/dpoint3d.hh> 00037 # include <mln/convert/from_to.hh> 00038 00039 00040 namespace mln 00041 { 00042 00047 // 00048 typedef window<mln::dpoint3d> window3d; 00049 00052 00073 const window3d& win_c4p_3d(); 00074 00077 00097 const window3d& win_c8p_3d(); 00098 00099 00100 00101 namespace convert 00102 { 00103 00104 namespace over_load 00105 { 00106 00107 template <unsigned M> 00108 void from_to_(bool const (&values)[M], window3d& win); 00109 00110 } // end of namespace mln::convert::over_load 00111 00112 } // end of namespace mln::convert 00113 00114 00115 00116 # ifndef MLN_INCLUDE_ONLY 00117 00118 inline const window3d& 00119 win_c4p_3d() 00120 { 00121 static window3d it; 00122 if (it.size() == 0) 00123 { 00124 it 00125 .insert(0, 0, -1) 00126 .insert(0, -1, 0) 00127 .insert(0, 0, 0) 00128 .insert(0, +1, 0) 00129 .insert(0, 0, +1); 00130 } 00131 return it; 00132 } 00133 00134 inline const window3d& 00135 win_c8p_3d() 00136 { 00137 static window3d it; 00138 if (it.size() == 0) 00139 { 00140 it 00141 .insert(0, -1, -1) 00142 .insert(0, 0, -1) 00143 .insert(0, +1, -1) 00144 .insert(0, -1, 0) 00145 .insert(0, 0, 0) 00146 .insert(0, +1, 0) 00147 .insert(0, -1, +1) 00148 .insert(0, 0, +1) 00149 .insert(0, +1, +1); 00150 } 00151 return it; 00152 } 00153 00154 namespace convert 00155 { 00156 00157 namespace over_load 00158 { 00159 00160 template <unsigned M> 00161 void 00162 from_to_(bool const (&values)[M], window3d& win) 00163 { 00164 const int h = unsigned(std::pow(float(M), float(1. / 3.))) / 2; 00165 mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == M); 00166 win.clear(); 00167 unsigned i = 0; 00168 for (int sli = - h; sli <= h; ++sli) 00169 for (int row = - h; row <= h; ++row) 00170 for (int col = - h; col <= h; ++col) 00171 if (values[i++]) 00172 win.insert(sli, row, col); 00173 } 00174 00175 } // end of namespace mln::convert::over_load 00176 00177 } // end of namespace mln::convert 00178 00179 # endif // ! MLN_INCLUDE_ONLY 00180 00181 00182 } // end of namespace mln 00183 00184 00185 #endif // ! MLN_CORE_ALIAS_WINDOW3D_HH