Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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_INTERNAL_NEIGHBORHOOD_BASE_HH 00027 # define MLN_CORE_INTERNAL_NEIGHBORHOOD_BASE_HH 00028 00035 00036 # include <mln/core/concept/neighborhood.hh> 00037 # include <mln/core/concept/window.hh> 00038 00039 00040 namespace mln 00041 { 00042 00043 00044 // Forward declaration. 00045 namespace win 00046 { 00047 template <unsigned n, typename W, typename F> 00048 class multiple_size; 00049 } 00050 00051 00052 namespace internal 00053 { 00054 00055 template <typename W, typename E> 00056 struct neighborhood_extra_impl 00057 : public Neighborhood<E> 00058 { 00059 }; 00060 00061 template <typename W, typename F, typename E> 00062 struct neighborhood_extra_impl< win::multiple_size<2,W,F>, E > 00063 : public Neighborhood<E> 00064 { 00065 00069 00070 neighb<W> foreground() const 00071 { 00072 W win = internal::force_exact<E>(*this).win().window_(1); // True, so object. 00073 neighb<W> nbh(win); 00074 return nbh; 00075 } 00076 00080 00081 neighb<W> background() const 00082 { 00083 W win = internal::force_exact<E>(*this).win().window_(0); // False, so background. 00084 neighb<W> nbh(win); 00085 return nbh; 00086 } 00087 00088 }; 00089 00090 00091 00092 00093 template <typename W, typename E> 00094 struct neighborhood_impl : public neighborhood_extra_impl<W,E> 00095 { 00096 // Optional methods... 00097 00100 unsigned size() const; 00101 00104 unsigned delta() const; 00105 00108 const mln_dpsite(W)& dp(unsigned i) const; 00109 00110 // end of Optional methods. 00111 }; 00112 00113 00117 00118 template <typename W, typename E> 00119 struct neighborhood_base : public neighborhood_impl<W,E> 00120 { 00122 typedef W window; 00123 00125 typedef mln_dpsite(W) dpsite; 00126 00128 typedef mln_psite(W) psite; 00129 00131 typedef mln_site(W) site; 00132 00134 bool is_valid() const; 00135 00136 protected: 00137 neighborhood_base(); 00138 }; 00139 00140 00141 00142 00143 # ifndef MLN_INCLUDE_ONLY 00144 00145 00146 // neighborhood_base 00147 00148 template <typename W, typename E> 00149 inline 00150 neighborhood_base<W,E>::neighborhood_base() 00151 { 00152 } 00153 00154 template <typename W, typename E> 00155 inline 00156 bool 00157 neighborhood_base<W,E>::is_valid() const 00158 { 00159 return true; 00160 } 00161 00162 // neighborhood_impl 00163 00164 template <typename W, typename E> 00165 inline 00166 unsigned 00167 neighborhood_impl<W,E>::size() const 00168 { 00169 mlc_is(mln_trait_window_size(W), 00170 trait::window::size::fixed)::check(); 00171 return exact(this)->win().size(); 00172 } 00173 00174 template <typename W, typename E> 00175 inline 00176 unsigned 00177 neighborhood_impl<W,E>::delta() const 00178 { 00179 mlc_is(mln_trait_window_support(W), 00180 trait::window::support::regular)::check(); 00181 mlc_is_not(mln_trait_window_definition(W), 00182 trait::window::definition::varying)::check(); 00183 return exact(this)->win().delta(); 00184 } 00185 00186 template <typename W, typename E> 00187 inline 00188 const mln_dpsite(W)& 00189 neighborhood_impl<W,E>::dp(unsigned i) const 00190 { 00191 mlc_is(mln_trait_window_support(W), 00192 trait::window::support::regular)::check(); 00193 mlc_is(mln_trait_window_definition(W), 00194 trait::window::definition::unique)::check(); 00195 return exact(this)->win().dp(i); 00196 } 00197 00198 # endif // ! MLN_INCLUDE_ONLY 00199 00200 } // end of namespace mln::internal 00201 00202 } // end of namespace mln 00203 00204 00205 #endif // ! MLN_CORE_INTERNAL_NEIGHBORHOOD_BASE_HH