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 #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
00052
00053
00054
00061 unsigned len(unsigned i) const;
00062
00063
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
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;
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
00171 return ! exact(this)->is_valid();
00172 }
00173
00174
00175
00176
00177 template <typename Bl, typename Br>
00178 inline
00179 bool operator<=(const Box<Bl>& lhs_, const Box<Br>& rhs_)
00180 {
00181
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
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 }
00205
00206
00207 #endif // ! MLN_CORE_CONCEPT_BOX_HH