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
00027
00028 #ifndef OLENA_LRDE_UFMT_ATTRIBUTES_HH
00029 # define OLENA_LRDE_UFMT_ATTRIBUTES_HH
00030
00031 # include <oln/core/abstract/image.hh>
00032 # include <oln/core/point2d.hh>
00033
00034
00035 namespace oln
00036 {
00037
00038 namespace lrde
00039 {
00040
00041 namespace ufmt
00042 {
00043
00044
00045
00046
00047 template <class A>
00048 struct node_
00049 {
00050 typedef node_<A> self_t;
00051
00052 A attr;
00053 unsigned par;
00054
00055
00056
00057 node_()
00058 {}
00059
00060 template <class I, class P>
00061 void init(const abstract::image<I>& f, const P& p)
00062 {
00063 attr.init(f, p);
00064 }
00065
00066 template <class I, class P>
00067 void insert(const abstract::image<I>& f, const P& p)
00068 {
00069
00070
00071
00072 attr.insert(f, p);
00073 }
00074
00075 void embrace(const self_t& rhs)
00076 {
00077
00078
00079
00080 attr.embrace(rhs.attr);
00081 }
00082 };
00083
00084 template <>
00085 struct node_ <void>
00086 {
00087 unsigned par;
00088 };
00089
00090
00091 struct card_t
00092 {
00093 typedef card_t self_t;
00094
00095 template <class I, class P>
00096 void init(const I&, const P&)
00097 {
00098 value = 1;
00099 }
00100 template <class I, class P>
00101 void insert(const I&, const P&)
00102 {
00103 ++value;
00104 }
00105 void embrace(const self_t& rhs)
00106 {
00107 value += rhs.value;
00108 }
00109 operator unsigned() const
00110 {
00111 return value;
00112 }
00113
00114 private:
00115 unsigned value;
00116 };
00117
00118
00119 struct mass_t
00120 {
00121 typedef mass_t self_t;
00122
00123 template <class I, class P>
00124 void init(const I& f, const P& p)
00125 {
00126 h = f[p];
00127 card = 1;
00128 value = 1;
00129 }
00130 template <class I, class P>
00131 void insert(const I& f, const P& p)
00132 {
00133 assert(f[p] == h);
00134 ++card;
00135 ++value;
00136 }
00137 void embrace(const self_t& rhs)
00138 {
00139 assert(rhs.h > h);
00140 value += (rhs.h - h) * rhs.card;
00141 card += rhs.card;
00142 }
00143 operator unsigned() const
00144 {
00145 return value;
00146 }
00147
00148 unsigned card;
00149
00150 private:
00151 unsigned h, value;
00152 };
00153
00154
00155 struct bbox2d_t
00156 {
00157 typedef bbox2d_t self_t;
00158 point2d min, max;
00159
00160 template <class I>
00161 void init(const I&, const point2d& p)
00162 {
00163 min = p;
00164 max = p;
00165 }
00166 template <class I>
00167 void insert(const I&, const point2d& p)
00168 {
00169
00170 if (p.row() > max.row())
00171 max.row() = p.row();
00172 else if (p.row() < min.row())
00173 min.row() = p.row();
00174
00175 if (p.col() > max.col())
00176 max.col() = p.col();
00177 else if (p.col() < min.col())
00178 min.col() = p.col();
00179 }
00180 void embrace(const self_t& rhs)
00181 {
00182
00183 if (rhs.min.row() < min.row())
00184 min.row() = rhs.min.row();
00185 if (rhs.min.col() < min.col())
00186 min.col() = rhs.min.col();
00187
00188 if (rhs.max.row() > max.row())
00189 max.row() = rhs.max.row();
00190 if (rhs.max.col() > max.col())
00191 max.col() = rhs.max.col();
00192 }
00193 unsigned width() const
00194 {
00195 return max.col() - min.col();
00196 }
00197 unsigned height() const
00198 {
00199 return max.row() - min.row();
00200 }
00201 };
00202
00203
00204
00205 struct hdome_t
00206 {
00207 typedef hdome_t self_t;
00208
00209 template <class I, class P>
00210 void init(const I& f, const P& p)
00211 {
00212 h = f[p];
00213 value = 0;
00214 }
00215 template <class I, class P>
00216 void insert(const I& f, const P& p)
00217 {
00218 assert(f[p] == h);
00219 }
00220 void embrace(const self_t& rhs)
00221 {
00222 assert(rhs.h > h);
00223 if (rhs.value + (rhs.h - h) > value)
00224 value = rhs.value + (rhs.h - h);
00225 }
00226 operator unsigned() const
00227 {
00228 return value;
00229 }
00230
00231 unsigned h;
00232 private:
00233 unsigned value;
00234 };
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 }
00274
00275 }
00276
00277 }
00278
00279
00280 #endif // ! OLENA_LRDE_UFMT_ATTRIBUTES_HH