window_base.hh

00001 // Copyright (C) 2001, 2002, 2003, 2004  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library 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
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
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; // forwarding declaration
00047   } // end of abstract
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       // friend class window_base_friend_traits<Sup>::ret;
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   } // end of abstract
00277 } // end of oln
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

Generated on Thu Apr 15 20:13:15 2004 for Olena by doxygen 1.3.6-20040222