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
00028 #ifndef OLENA_CORE_ABSTRACT_WINDOW_BASE_HH
00029 # define OLENA_CORE_ABSTRACT_WINDOW_BASE_HH
00030
00031 # include <mlc/contract.hh>
00032 # include <mlc/is_a.hh>
00033 # include <mlc/bool.hh>
00034 # include <oln/core/abstract/window.hh>
00035 # include <oln/core/abstract/w_window.hh>
00036 # include <oln/core/abstract/neighborhood.hh>
00037 # include <oln/core/accum.hh>
00038 # include <iostream>
00039 # include <vector>
00040 # include <utility>
00041
00042 namespace oln {
00043
00044 namespace abstract {
00045 template<class Sup, class Exact>
00046 struct window_base;
00047 }
00048
00052 template<class Sup, class Exact>
00053 struct struct_elt_traits<abstract::window_base<Sup, Exact> >: public struct_elt_traits<Sup>
00054 {
00055
00056 };
00057
00061 template<class Sup>
00062 struct window_base_friend_traits;
00063
00067 template< class Exact>
00068 struct window_base_friend_traits< abstract::neighborhood<Exact> >
00069 {
00070 typedef abstract::neighborhood<Exact> ret;
00071 };
00072
00076 template< class Exact>
00077 struct window_base_friend_traits< abstract::window<Exact> >
00078 {
00079 typedef abstract::struct_elt<Exact> ret;
00080 };
00081
00085 template< class Exact>
00086 struct window_base_friend_traits< abstract::w_window<Exact> >
00087 {
00088 typedef abstract::struct_elt<Exact> ret;
00089 };
00090
00091 namespace abstract
00092 {
00093
00102 template<class Sup, class Exact>
00103 struct window_base: public Sup
00104 {
00105 enum { dim = struct_elt_traits<Exact >::dim };
00107 typedef window_base<Sup, Exact> self_type;
00109
00115 typedef typename struct_elt_traits<Exact>::point_type point_type;
00116
00122 typedef typename struct_elt_traits<Exact>::dpoint_type dpoint_type;
00123
00124 typedef Exact exact_type;
00126 typedef Sup super_type;
00128
00133 friend class struct_elt<Exact>;
00134 friend class neighborhood<Exact>;
00135
00136
00138 static std::string
00139 name()
00140 {
00141 return std::string("window_base<") + Exact::name() + ">";
00142 }
00143
00144 protected:
00145
00151 bool
00152 has_(const dpoint_type& dp) const
00153 {
00154 return std::find(dp_.begin(), dp_.end(), dp) != dp_.end();
00155 }
00156
00161 unsigned
00162 card_() const
00163 {
00164 return dp_.size();
00165 }
00166
00175 bool
00176 is_centered_() const
00177 {
00178 return centered_;
00179 }
00180
00186 bool
00187 is_equal(const exact_type& win) const
00188 {
00189 for (typename std::vector<dpoint_type>::const_iterator it = dp_.begin(); it != dp_.end(); ++it)
00190 if (std::find(win.dp_.begin(), win.dp_.end(), *it) == win.dp_.end())
00191 return false;
00192 return true;
00193 }
00194
00201 coord
00202 get_delta() const
00203 {
00204 return delta_;
00205 }
00206
00215 coord
00216 delta_update(const dpoint_type& dp)
00217 {
00218 return this->exact().delta_update_(dp);
00219 }
00220
00226 void
00227 sym_()
00228 {
00229 for (unsigned i = 0; i < this->card(); ++i)
00230 dp_[i] = - dp_[i];
00231 }
00232
00239 const dpoint_type
00240 at(unsigned i) const
00241 {
00242 precondition(i < this->card());
00243 return dp_[i];
00244 }
00245
00251 window_base() : super_type(), dp_(), delta_(0)
00252 {
00253 centered_ = false;
00254 }
00255
00263 window_base(unsigned size) : super_type(), dp_(), delta_(0)
00264 {
00265 dp_.reserve(size);
00266 centered_ = false;
00267 }
00268
00269 std::vector<dpoint_type> dp_;
00270 max_accumulator<coord> delta_;
00271 bool centered_;
00272
00273 };
00274
00275
00276 }
00277 }
00278
00287 template<class Sup, class Exact>
00288 std::ostream&
00289 operator<<(std::ostream& o, const oln::abstract::window_base<Sup, Exact>& w)
00290 {
00291 unsigned c = w.card();
00292 o << "[";
00293 for (unsigned i = 0; i < c; ++i)
00294 o << w.dp(i);
00295 o << "]";
00296 return o;
00297 }
00298
00299 #endif // OLENA_CORE_ABSTRACT_WINDOW_BASE_HH