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_CONVERT_TO_P_SET_HH 00027 # define MLN_CONVERT_TO_P_SET_HH 00028 00032 00033 # include <set> 00034 00035 # include <mln/core/concept/neighborhood.hh> 00036 # include <mln/core/concept/window.hh> 00037 # include <mln/core/concept/point_site.hh> 00038 # include <mln/core/site_set/p_set.hh> 00039 # include <mln/pw/image.hh> 00040 # include <mln/pw/cst.hh> 00041 # include <mln/metal/templated_by.hh> 00042 # include <mln/metal/is_a.hh> 00043 00044 00045 namespace mln 00046 { 00047 00048 namespace convert 00049 { 00050 00052 template <typename N> 00053 p_set<mln_psite(N)> 00054 to_p_set(const Neighborhood<N>& nbh); 00055 00057 template <typename I> 00058 p_set<mln_psite(I)> 00059 to_p_set(const Image<I>& ima); 00060 00062 template <typename W> 00063 p_set<mln_psite(W)> 00064 to_p_set(const Window<W>& win); 00065 00068 template <typename P, typename C> 00069 p_set<P> 00070 to_p_set(const std::set<P, C>& s); 00071 00073 template <typename S> 00074 p_set<mln_psite(S)> 00075 to_p_set(const Site_Set<S>& ps); 00076 00077 00078 # ifndef MLN_INCLUDE_ONLY 00079 00080 template <typename N> 00081 inline 00082 p_set<mln_psite(N)> 00083 to_p_set(const Neighborhood<N>& nbh_) 00084 { 00085 const N& nbh = exact(nbh_); 00086 typedef mln_psite(N) P; 00087 p_set<P> pset; 00088 mln_niter(N) n(nbh, P::origin); 00089 for_all(n) 00090 pset.insert(n); 00091 return pset; 00092 } 00093 00094 template <typename I> 00095 inline 00096 p_set<mln_psite(I)> 00097 to_p_set(const Image<I>& ima_) 00098 { 00099 const I& ima = exact(ima_); 00100 mln_precondition(ima.is_valid()); 00101 00102 // FIXME: Check that ima is binary! 00103 // mln::metal::templated_by<mln_value(I), bool >::check(); 00104 00105 typedef mln_psite(I) P; 00106 p_set<P> pset; 00107 mln_piter(I) p(ima.domain()); 00108 for_all(p) 00109 if (ima(p)) 00110 pset.insert(p); 00111 return pset; 00112 } 00113 00114 template <typename W> 00115 inline 00116 p_set<mln_psite(W)> 00117 to_p_set(const Window<W>& win) 00118 { 00119 typedef mln_psite(W) P; 00120 p_set<P> pset; 00121 mln_qiter(W) q(exact(win), P::origin); 00122 for_all(q) 00123 pset.insert(q); 00124 return pset; 00125 } 00126 00127 template <typename P, typename C> 00128 inline 00129 p_set<P> 00130 to_p_set(const std::set<P, C>& s) 00131 { 00132 P titi; 00133 mln::metal::is_a<P, Site>::check(); 00134 p_set<P> pset; 00135 for (typename std::set<P, C>::const_iterator i = s.begin(); 00136 i != s.end(); ++i) 00137 pset.insert(*i); 00138 return pset; 00139 } 00140 00141 template <typename S> 00142 inline 00143 p_set<mln_psite(S)> 00144 to_p_set(const Site_Set<S>& ps_) 00145 { 00146 const S& ps = exact(ps_); 00147 p_set<mln_psite(S)> tmp; 00148 mln_piter(S) p(ps); 00149 for_all(p) 00150 tmp.insert(p); 00151 return tmp; 00152 } 00153 00154 # endif // ! MLN_INCLUDE_ONLY 00155 00156 } // end of namespace mln::convert 00157 00158 } // end of namespace mln 00159 00160 00161 #endif // ! MLN_CONVERT_TO_P_SET_HH