attributes.hh

00001 // Copyright (C) 2006  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016 // Boston, MA 02110-1301, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
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       // FIXME: doc.
00046 
00047       template <class A>
00048       struct node_
00049       {
00050         typedef node_<A> self_t;
00051 
00052         A attr;  // attribute(s)
00053         unsigned par; // parent label
00054 
00055         // ctors
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           // for the max-tree:
00070           //   p belongs to the same node than init.p
00071           //   so f(p) == f(init.p)
00072           attr.insert(f, p);
00073         }
00074 
00075         void embrace(const self_t& rhs)
00076         {
00077           // for the max-tree:
00078           //   this node is the parent node of rhs
00079           //   so h(this node) < h(rhs)
00080           attr.embrace(rhs.attr);
00081         }
00082       };
00083 
00084       template <>
00085       struct node_ <void>
00086       {
00087         unsigned par; // parent label
00088       };
00089 
00090 
00091       struct card_t // is area for 2D images
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 // is volume for 2D images
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           // row
00170           if (p.row() > max.row())
00171             max.row() = p.row();
00172           else if (p.row() < min.row())
00173             min.row() = p.row();
00174           // col
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           // min
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           // max
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 // delta level to the highest point
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 //       struct montparnasse_t // FIXME: explain...
00238 //       {
00239 //      typedef montparnasse_t self_t;
00240 
00241 //      template <class I, class P>
00242 //      void init(const I& f, const P& p)
00243 //      {
00244 //        hdome.init(f, p);
00245 //        mass.init(f, p);
00246 //      }
00247 //      template <class I, class P>
00248 //      void insert(const I& f, const P& p)
00249 //      {
00250 //        assert(f[p] == hdome.h);
00251 //        hdome.insert(f, p);
00252 //        mass.insert(f, p);
00253 //      }
00254 //      void embrace(const self_t& rhs)
00255 //      {
00256 //        assert(rhs.h > hdome.h);
00257 //        hdome.embrace(f, p);
00258 //        mass.embrace(f, p);
00259 //      }
00260 //      operator float() const
00261 //      {
00262 //        static const float epsilon = 1e-7; // FIXME
00263 //        float tmp = float(mass) / (mass.card * (hdome + 1));
00264 //        assert(tmp > - epsilon and tmp < 1.f + epsilon);
00265 //      }
00266 
00267 //       private:
00268 //      hdome_t hdome;
00269 //      mass_t mass;
00270 //       };
00271 
00272 
00273     } // end of namespace oln::lrde::ufmt
00274 
00275   } // end of namespace oln::lrde
00276 
00277 } // end of namespace oln
00278 
00279 
00280 #endif // ! OLENA_LRDE_UFMT_ATTRIBUTES_HH

Generated on Tue Feb 20 20:18:01 2007 for Olena by  doxygen 1.5.1