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_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 ? static_cast<unsigned>(1 + exact(this)->pmax()[i] 00136 - exact(this)->pmin()[i]) 00137 : 0u; 00138 } 00139 00140 template <typename E> 00141 inline 00142 Box<E>::Box() 00143 { 00144 typedef mln_site(E) site; 00145 site (E::*m1)() const = & E::pmin; 00146 m1 = 0; 00147 site (E::*m2)() const = & E::pmax; 00148 m2 = 0; 00149 } 00150 00151 template <typename E> 00152 inline 00153 unsigned 00154 Box<E>::nsites() const 00155 { 00156 if (! exact(this)->is_valid()) 00157 return 0; 00158 unsigned count = 1; 00159 typedef mln_site(E) P; // Helps g++-3.3.5. 00160 for (unsigned i = 0; i < P::dim; ++i) 00161 count *= exact(this)->len(i); 00162 return count; 00163 } 00164 00165 template <typename E> 00166 inline 00167 bool 00168 Box<E>::is_empty() const 00169 { 00170 // A non-valid box is empty. 00171 return ! exact(this)->is_valid(); 00172 } 00173 00174 00175 // Operators. 00176 00177 template <typename Bl, typename Br> 00178 inline 00179 bool operator<=(const Box<Bl>& lhs_, const Box<Br>& rhs_) 00180 { 00181 // FIXME: Same grid! 00182 const Bl& lhs = exact(lhs_); 00183 const Br& rhs = exact(rhs_); 00184 typedef mln_site(Bl) P; 00185 for (unsigned i = 0; i < P::dim; ++i) 00186 if (lhs.pmin()[i] < rhs.pmin()[i] || 00187 lhs.pmax()[i] > rhs.pmax()[i]) 00188 return false; 00189 return true; 00190 } 00191 00192 template <typename Bl, typename Br> 00193 inline 00194 bool operator<(const Box<Bl>& lhs_, const Box<Br>& rhs_) 00195 { 00196 // FIXME: Same grid! 00197 const Bl& lhs = exact(lhs_); 00198 const Br& rhs = exact(rhs_); 00199 return lhs <= rhs && ! (lhs == rhs); 00200 } 00201 00202 # endif // ! MLN_INCLUDE_ONLY 00203 00204 } // end of namespace mln 00205 00206 00207 #endif // ! MLN_CORE_CONCEPT_BOX_HH