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 ? 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;
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
00170 return ! exact(this)->is_valid();
00171 }
00172
00173
00174
00175
00176 template <typename Bl, typename Br>
00177 inline
00178 bool operator<=(const Box<Bl>& lhs_, const Box<Br>& rhs_)
00179 {
00180
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
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 }
00204
00205
00206 #endif // ! MLN_CORE_CONCEPT_BOX_HH