• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

box.hh

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_CONCEPT_BOX_HH
00027 # define MLN_CORE_CONCEPT_BOX_HH
00028 
00032 
00033 # include <mln/core/concept/site_set.hh>
00034 
00035 
00036 namespace mln
00037 {
00038 
00047   template <typename E>
00048   struct Box : public Site_Set<E>
00049   {
00050     /*
00051       const site& pmin() const;
00052       const site& pmax() const;
00053     */
00054 
00061     unsigned len(unsigned i) const;
00062 
00063     // Box associated type.
00064     typedef const E& q_box;
00065 
00073     const E& bbox() const;
00074 
00082     unsigned nsites() const;
00083 
00085     bool is_empty() const;
00086 
00087   protected:
00088     Box();
00089   };
00090 
00091 
00092 
00093 
00101   template <typename Bl, typename Br>
00102   bool operator<=(const Box<Bl>& lhs, const Box<Br>& rhs);
00103 
00104 
00112   template <typename Bl, typename Br>
00113   bool operator<(const Box<Bl>& lhs, const Box<Br>& rhs);
00114 
00115 
00116 
00117 
00118 # ifndef MLN_INCLUDE_ONLY
00119 
00120   // Box<E>
00121 
00122   template <typename E>
00123   inline
00124   const E& Box<E>::bbox() const
00125   {
00126     return exact(*this);
00127   }
00128 
00129   template <typename E>
00130   inline
00131   unsigned Box<E>::len(unsigned i) const
00132   {
00133     return
00134       exact(this)->is_valid()
00135       ? 1 + exact(this)->pmax()[i] - exact(this)->pmin()[i]
00136       : 0u;
00137   }
00138 
00139   template <typename E>
00140   inline
00141   Box<E>::Box()
00142   {
00143     typedef mln_site(E) site;
00144     site (E::*m1)() const = & E::pmin;
00145     m1 = 0;
00146     site (E::*m2)() const = & E::pmax;
00147     m2 = 0;
00148   }
00149 
00150   template <typename E>
00151   inline
00152   unsigned
00153   Box<E>::nsites() const
00154   {
00155     if (! exact(this)->is_valid())
00156       return 0;
00157     unsigned count = 1;
00158     typedef mln_site(E) P; // Helps g++-3.3.5.
00159     for (unsigned i = 0; i < P::dim; ++i)
00160       count *= exact(this)->len(i);
00161     return count;
00162   }
00163 
00164   template <typename E>
00165   inline
00166   bool
00167   Box<E>::is_empty() const
00168   {
00169     // A non-valid box is empty.
00170     return ! exact(this)->is_valid();
00171   }
00172 
00173 
00174   // Operators.
00175 
00176   template <typename Bl, typename Br>
00177   inline
00178   bool operator<=(const Box<Bl>& lhs_, const Box<Br>& rhs_)
00179   {
00180     // FIXME: Same grid!
00181     const Bl& lhs = exact(lhs_);
00182     const Br& rhs = exact(rhs_);
00183     typedef mln_site(Bl) P;
00184     for (unsigned i = 0; i < P::dim; ++i)
00185       if (lhs.pmin()[i] < rhs.pmin()[i] ||
00186           lhs.pmax()[i] > rhs.pmax()[i])
00187         return false;
00188     return true;
00189   }
00190 
00191   template <typename Bl, typename Br>
00192   inline
00193   bool operator<(const Box<Bl>& lhs_, const Box<Br>& rhs_)
00194   {
00195     // FIXME: Same grid!
00196     const Bl& lhs = exact(lhs_);
00197     const Br& rhs = exact(rhs_);
00198     return lhs <= rhs && ! (lhs == rhs);
00199   }
00200 
00201 # endif // ! MLN_INCLUDE_ONLY
00202 
00203 } // end of namespace mln
00204 
00205 
00206 #endif // ! MLN_CORE_CONCEPT_BOX_HH

Generated on Fri Sep 16 2011 16:33:20 for Milena (Olena) by  doxygen 1.7.1