attributes.hh

00001 // Copyright (C) 2001, 2002, 2003, 2004  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, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, 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 OLN_MORPHO_ATTRIBUTES_HH
00029 # define OLN_MORPHO_ATTRIBUTES_HH
00030 # include <oln/basics.hh>
00031 # include <mlc/type.hh>
00032 # include <vector>
00033 # include <oln/morpho/environments.hh>
00034 
00035 // attribute dedicated macros
00036 # define attr_lambda_type(T)    typename oln::morpho::attr::attr_traits< T >::lambda_type
00037 # define attr_env_type(T)       typename oln::morpho::attr::attr_traits< T >::env_type
00038 # define attr_value_type(T)     typename oln::morpho::attr::attr_traits< T >::value_type
00039 
00040 # define attr_lambda_type_(T)    oln::morpho::attr::attr_traits< T >::lambda_type
00041 # define attr_env_type_(T)       oln::morpho::attr::attr_traits< T >::env_type
00042 # define attr_value_type_(T)     oln::morpho::attr::attr_traits< T >::value_type
00043 
00044 
00045 # define attr_type_decl(self_type) \
00046       typedef mlc_exact_vt_type(self_type, Exact)       exact_type; \
00047       typedef attr_value_type(exact_type)               value_type; \
00048       typedef attr_env_type(exact_type)                 env_type; \
00049       typedef attr_lambda_type(exact_type)              lambda_type
00050 
00051 namespace oln {
00052   namespace morpho {
00055     namespace attr {
00058       namespace tools {
00059 
00064         template <class T>
00065         T diffabs(const T &v1, const T &v2)
00066         {
00067           return v1 > v2 ? v1 - v2 : v2 - v1;
00068         }
00069       } // !tools
00070 
00071 
00072       // the traits fwd declaration
00077       template <class T>
00078       struct attr_traits;
00079 
00087       template <class In, class Exact>
00088       struct change_exact;
00089 
00090 
00091       // the attributes hierarchy
00092 
00093       /*------------*
00094         | attribute |
00095         *-----------*/
00101       template <class Exact>
00102       class attribute: public mlc_hierarchy::any<Exact>
00103       {
00104       public:
00105         typedef attribute<Exact>        self_type; /*< Self type of the class.*/
00106         attr_type_decl(self_type);
00107 
00114         void operator+=(const exact_type &rhs)
00115         {
00116           mlc_dispatch(pe)(rhs);
00117         };
00118 
00124         bool operator>=(const lambda_type &lambda) const
00125         {
00126           mlc_dispatch(ge)(lambda);
00127         };
00128 
00135         bool operator<(const lambda_type &lambda) const
00136         {
00137           mlc_dispatch(less)(lambda);
00138         };
00139 
00146         bool operator<(const exact_type &x) const
00147         {
00148           mlc_dispatch(less2)(x);
00149         };
00150 
00157         bool operator!=(const lambda_type &lambda) const
00158         {
00159           mlc_dispatch(ne)(lambda);
00160         };
00161 
00167         const lambda_type &toLambda() const
00168         {
00169           mlc_dispatch(toLambda)();
00170         };
00171 
00179         bool ge_impl(const lambda_type &lambda) const
00180         {
00181           return !(*this < lambda);
00182         };
00183 
00191         bool less2_impl(const exact_type &x) const
00192         {
00193           return *this < x.toLambda();
00194         };
00195 
00196 
00197 
00198       protected:
00199         attribute() {};
00200 
00201       };
00202 
00203       /*-----------*
00204         |   card    |
00205         *-----------*/
00206 
00212       template <class T = unsigned, class Exact = mlc::final>
00213       class card_type:
00214         public attribute<mlc_2_exact_vt_type(card_type, T, Exact)>
00215       {
00216       public:
00217         typedef card_type<T, Exact>                     self_type; 
00218         attr_type_decl(self_type);
00219 
00226         card_type()
00227           {
00228           };
00229 
00233         card_type(const lambda_type &lambda): value_(lambda)
00234           {
00235           };
00236 
00242         template <class I>
00243           card_type(const abstract::image<I>&,
00244                     const oln_point_type(I)&,
00245                     const env_type&):
00246           value_(ntg_unit_val(value_type))
00247           {
00248           };
00249 
00250 
00258         void pe_impl(const self_type &rhs)
00259           {
00260             value_ += rhs.value_;
00261           };
00262 
00270         bool less_impl(const lambda_type &lambda) const
00271           {
00272             return value_ < lambda;
00273           };
00274 
00282         bool ne_impl(const lambda_type &lambda) const
00283           {
00284             return lambda != value_;
00285           };
00286 
00294         const lambda_type &toLambda_impl() const
00295         {
00296           return value_;
00297         };
00298 
00299       protected:
00300         value_type value_; 
00301       };
00302 
00303       /*-------------------------------*
00304         | card with info on other image |
00305         *------------------------------*/
00306       template <class I, class T = unsigned, class Exact = mlc::final>
00307       class card_full_type: public card_type<T,
00308                                              typename mlc::exact_vt<card_full_type<I,
00309                                                                                    T,
00310                                                                                    Exact>,
00311                                                                     Exact>::ret>
00312       {
00313       public:
00314         typedef card_full_type<I, T, Exact>                     self_type; 
00315         attr_type_decl(self_type);
00316         typedef card_type<T, exact_type>                        super_type; 
00317 
00324         card_full_type(): super_type()
00325           {
00326           };
00327 
00331         card_full_type(const lambda_type &lambda): super_type(lambda)
00332           {
00333           };
00334 
00340         template <class I2>
00341           card_full_type(const abstract::image<I2> &im,
00342                     const oln_point_type(I2) &p,
00343                     const env_type &env): super_type(im, p, env)
00344           {
00345           };
00346       };
00347 
00348       /*--------------*
00349         |  integral   |
00350         *------------*/
00351 
00357       template <class T = unsigned, class Exact = mlc::final>
00358       class integral_type:
00359         public attribute<mlc_2_exact_vt_type(integral_type, T, Exact)>
00360       {
00361       public:
00362         typedef integral_type<T, Exact>                 self_type; 
00363         attr_type_decl(self_type);
00364 
00371         integral_type()
00372           {
00373           };
00374 
00378         integral_type(const lambda_type &lambda): value_(lambda)
00379           {
00380           };
00381 
00385         template <class I>
00386           integral_type(const abstract::image<I> &input,
00387                         const oln_point_type(I) &p,
00388                         const env_type &) :
00389           reflevel_(input[p]),
00390           area_(ntg_unit_val(value_type)),
00391           value_(ntg_unit_val(value_type))
00392           {
00393           };
00394 
00395         // interface part
00402         const value_type &getValue() const
00403           {
00404             mlc_dispatch(getValue)();
00405           };
00406 
00412         const value_type &getReflevel() const
00413           {
00414             mlc_dispatch(getReflevel)();
00415           };
00416 
00422         const value_type &getArea() const
00423           {
00424             mlc_dispatch(getArea)();
00425           };
00426 
00427         // impl part
00436         const value_type &getValue_impl() const
00437           {
00438             return value_;
00439           };
00440 
00449         const value_type &getReflevel_impl() const
00450           {
00451             return reflevel_;
00452           };
00453 
00462         const value_type &getArea_impl() const
00463           {
00464             return area_;
00465           };
00466 
00474         void pe_impl(const self_type &rhs)
00475           {
00476             value_ += rhs.getValue() + area_ * tools::diffabs(reflevel_, rhs.getReflevel());
00477             area_ += rhs.getArea();
00478           };
00479 
00487         bool less_impl(const lambda_type &lambda) const
00488           {
00489             return value_ < lambda;
00490           };
00491 
00499         bool ne_impl(const lambda_type &lambda) const
00500           {
00501             return lambda != value_;
00502           };
00503 
00504       protected:
00505         value_type reflevel_; 
00506         value_type area_; 
00507         value_type value_; 
00508       };
00509 
00510       /*-------------------*
00511         | other image_type |
00512         ------------------*/
00521       template <class Dad, class I, class Exact = mlc::final>
00522       class other_image:
00523         public change_exact<Dad, typename mlc::exact_vt<other_image<Dad, I, Exact>, Exact>::ret >::ret
00524       {
00525       public:
00526         typedef other_image<Dad, I,  Exact>                                             self_type; /*< Self type of the class.*/
00527         typedef typename abstract::image<mlc_exact_type(I)>                             im_type; /*< Type of substituted image.*/
00528         attr_type_decl(self_type);
00529         typedef typename change_exact<Dad,
00530                                       typename mlc::exact_vt<other_image<Dad, I, Exact>,
00531                                                              Exact>::ret >::ret         super_type; /*< Mother class type.*/
00532 
00538         other_image(): super_type()
00539         {
00540         };
00541 
00547         other_image(const lambda_type &lambda): super_type(lambda)
00548         {
00549         };
00550 
00557         template <typename IM>
00558         other_image(const abstract::image<IM> &,
00559                     const oln_point_type(I) &p,
00560                     const env_type & e): super_type(e.getImage(), p, e)
00561         {
00562         };
00563       };
00564 
00565       /*----------------------*
00566         | ball_parent_change |
00567         *--------------------*/
00576       template <class I, class Exact = mlc::final>
00577       class ball_parent_change:
00578         public attribute<mlc_2_exact_vt_type(ball_parent_change, I, Exact)>
00579       {
00580       public:
00581         typedef ball_parent_change<I,  Exact>                   self_type; /*< Self type of the class.*/
00582         typedef typename abstract::image<mlc_exact_type(I)>     im_type; /*< Type of substituted image.*/
00583         attr_type_decl(self_type);
00584         typedef oln_value_type(I)                               pts_type; 
00585         typedef typename pts_type::const_iterator               cst_iter_type; 
00586         typedef typename pts_type::value_type                   point_type; 
00587         typedef oln_dpoint_type(point_type)     dpoint_type; 
00588 
00594         ball_parent_change(): value_(ntg_zero_val(value_type)), points_()
00595         {
00596         };
00597 
00603         ball_parent_change(const lambda_type &lambda): value_(lambda), points_()
00604         {
00605         };
00606 
00613         template <typename IM>
00614         ball_parent_change(const abstract::image<IM> &,
00615                            const oln_point_type(IM) &p,
00616                            const env_type &e): points_()//: super_type(/*e.getImage(), */e.getPoint(p), e)
00617         {
00618           std::copy(e.getParent()[p].begin(),
00619                     e.getParent()[p].end(),
00620                     std::back_inserter(points_));
00621         };
00622 
00629         const value_type &getValue() const
00630           {
00631             mlc_dispatch(getValue)();
00632           };
00633 
00634 
00641         const pts_type &getPts() const
00642           {
00643             mlc_dispatch(getPts)();
00644           };
00645 
00646         // impl
00655         const value_type &getValue_impl() const
00656           {
00657             return value_;
00658           };
00659 
00668         const pts_type &getPts_impl() const
00669           {
00670             return points_;
00671           };
00672 
00680         void pe_impl(const self_type &rhs)
00681           {
00682             precondition(points_.size() < (128 * 128 * 128 + 1));
00683             std::copy(rhs.getPts().begin(),
00684                       rhs.getPts().end(),
00685                       std::back_inserter(points_));
00686             compute_value();
00687             value_ = ntg::max(value_, rhs.getValue());
00688           };
00689 
00697         bool less_impl(const lambda_type &lambda) const
00698           {
00699             return value_ < lambda;
00700           };
00701 
00709         bool ne_impl(const lambda_type &lambda) const
00710           {
00711             return lambda != value_;
00712           };
00713 
00714       protected:
00715         void compute_value()
00716           {
00717             value_type  last = value_;
00718             value_ = ntg_zero_val(value_type);
00719             for (cst_iter_type p1 = points_.begin(); p1 != points_.end(); ++p1)
00720               for (cst_iter_type p2 = points_.begin(); p2 != points_.end(); ++p2)
00721                 {
00722                   unsigned d = 0;
00723                   dpoint_type   p = *p1 - *p2;
00724                   for (int i = 0; i < point_traits<point_type>::dim; ++i)
00725                     d += p.nth(i) * p.nth(i);
00726                   if (d > value_)
00727                     value_ = d;
00728                 }
00729             value_ /= 2;
00730             value_ = ntg::max(value_, last);
00731           }
00732 
00733         value_type      value_;
00734         pts_type        points_;
00735       };
00736 
00737       /*-----------*
00738         |  height   |
00739         *-----------*/
00743       template <class T = unsigned, class Exact = mlc::final>
00744       class height_type:
00745         public attribute<mlc_2_exact_vt_type(height_type, T, Exact)>
00746       {
00747       public:
00748         typedef height_type<T, Exact>                   self_type;
00749         attr_type_decl(self_type);
00750 
00757         height_type()
00758           {
00759           };
00760 
00764         height_type(const lambda_type &lambda):
00765           value_(lambda),
00766           min_(ntg_zero_val(value_type)),
00767           max_(lambda)
00768           {
00769           };
00770 
00774         template <class I>
00775           height_type(const abstract::image<I> &input,
00776                       const oln_point_type(I) &p,
00777                       const env_type&):
00778           value_(ntg_zero_val(value_type)),
00779           min_(input[p]),
00780           max_(input[p])
00781           {
00782           };
00783 
00790         const value_type &getMin() const
00791           {
00792             mlc_dispatch(getMin)();
00793           };
00794 
00801         const value_type &getMax() const
00802           {
00803             mlc_dispatch(getMax)();
00804           };
00805 
00806         // impl part
00815         const value_type &getMin_impl() const
00816           {
00817             return min_;
00818           };
00819 
00828         const value_type &getMax_impl() const
00829           {
00830             return max_;
00831           };
00832 
00840         void pe_impl(const height_type &rhs)
00841           {
00842             min_ = ntg::min(min_, rhs.getMin());
00843             max_ = ntg::max(max_, rhs.getMax());
00844             value_ = max_ - min_;
00845           };
00846 
00854         bool less_impl(const lambda_type &lambda) const
00855           {
00856             return value_ < lambda;
00857           };
00858 
00866         bool ne_impl(const lambda_type &lambda) const
00867           {
00868             return lambda != value_;
00869           };
00870 
00871       protected:
00872         value_type      value_; 
00873         value_type      min_; 
00874         value_type      max_; 
00875       };
00876 
00877 
00878       /*-----------*
00879         | maxvalue  |
00880         *-----------*/
00886       template <class T = unsigned, class Exact = mlc::final>
00887       class maxvalue_type:
00888         public attribute<mlc_2_exact_vt_type(maxvalue_type, T, Exact)>
00889       {
00890       public:
00891         typedef maxvalue_type<T, Exact>                 self_type; 
00892         attr_type_decl(self_type);
00893 
00900         maxvalue_type()
00901           {
00902           };
00903 
00909         maxvalue_type(const lambda_type &lambda): value_(lambda)
00910           {
00911           };
00912 
00921         template <class I>
00922           maxvalue_type(const abstract::image<I> &input,
00923                         const oln_point_type(I) &p,
00924                         const env_type &):
00925           value_(input[p])
00926           {
00927           };
00928 
00935         const value_type &getValue() const
00936           {
00937             mlc_dispatch(getValue)();
00938           };
00939 
00948         const value_type &getValue_impl() const
00949           {
00950             return value_;
00951           };
00952 
00960         void pe_impl(const maxvalue_type &rhs)
00961           {
00962             value_ = ntg::max(value_, rhs.getValue());
00963           };
00964 
00972         bool less_impl(const lambda_type &lambda) const
00973           {
00974             return value_ < lambda;
00975           };
00976 
00984         bool ne_impl(const lambda_type &lambda) const
00985           {
00986             return lambda != value_;
00987           };
00988 
00989       protected:
00990         value_type value_; 
00991       };
00992 
00993 
00994       /*-----------*
00995         | minvalue  |
00996         *-----------*/
01002       template <class T = unsigned, class Exact = mlc::final>
01003       class minvalue_type:
01004         public attribute<mlc_2_exact_vt_type(minvalue_type, T, Exact)>
01005       {
01006       public:
01007         typedef minvalue_type<T, Exact>                 self_type;
01008         attr_type_decl(self_type);
01009 
01016         minvalue_type()
01017           {
01018           };
01019 
01025         minvalue_type(const lambda_type &lambda): value_(lambda)
01026           {
01027           };
01028 
01037         template <class I>
01038           minvalue_type(const abstract::image<I> &input,
01039                         const oln_point_type(I) &p,
01040                         const env_type &) :
01041           value_(input[p])
01042           {
01043           };
01044 
01051         const value_type &getValue() const
01052           {
01053             mlc_dispatch(getValue)();
01054           };
01055 
01064         const value_type &getValue_impl() const
01065           {
01066             return value_;
01067           };
01068 
01076         void pe_impl(const minvalue_type &rhs)
01077           {
01078             value_ = ntg::min(value_, rhs.getValue());
01079           };
01080 
01088         bool less_impl(const lambda_type &lambda) const
01089           {
01090             return value_ > lambda;
01091           };
01092 
01100         bool ne_impl(const lambda_type &lambda) const
01101           {
01102             return lambda != value_;
01103           };
01104 
01105       protected:
01106         value_type value_; 
01107       };
01108 
01109 
01110       /*-----------*
01111         |   ball    |
01112         *-----------*/
01118       template <class I, class Exact = mlc::final>
01119       class ball_type:
01120         public attribute<mlc_2_exact_vt_type(ball_type, I, Exact)>
01121       {
01122       public:
01123         typedef ball_type<I, Exact>                     self_type; 
01124         attr_type_decl(self_type);
01125         typedef abstract::image<mlc_exact_type(I)>      im_type; 
01126         typedef oln_point_type(im_type)                 point_type; 
01127         typedef oln_dpoint_type(im_type)                        dpoint_type; 
01128         typedef std::vector<point_type>                 pts_type; 
01129         typedef typename pts_type::const_iterator               cst_iter_type; 
01130 
01137         ball_type()
01138           {
01139           };
01140 
01146         ball_type(const lambda_type &lambda): value_(lambda), pts_()
01147           {
01148           };
01149 
01150 
01156         ball_type(const im_type&, const point_type &p, const env_type &) :
01157           value_(ntg_zero_val(value_type)), pts_()
01158 
01159           {
01160             pts_.push_back(p);
01161           };
01162 
01169         const value_type &getValue() const
01170           {
01171             mlc_dispatch(getValue)();
01172           };
01173 
01174 
01181         const pts_type &getPts() const
01182           {
01183             mlc_dispatch(getPts)();
01184           };
01185 
01186         // impl
01195         const value_type &getValue_impl() const
01196           {
01197             return value_;
01198           };
01199 
01208         const pts_type &getPts_impl() const
01209           {
01210             return pts_;
01211           };
01212 
01220         void pe_impl(const ball_type &rhs)
01221           {
01222             value_type  last = value_;
01223             std::copy(rhs.getPts().begin(),
01224                       rhs.getPts().end(),
01225                       std::back_inserter(pts_));
01226             value_ = ntg_zero_val(value_type);
01227             for (cst_iter_type p1 = pts_.begin(); p1 != pts_.end(); ++p1)
01228               for (cst_iter_type p2 = pts_.begin(); p2 != pts_.end(); ++p2)
01229                 {
01230                   unsigned d = 0;
01231                   dpoint_type   p = *p1 - *p2;
01232                   for (int i = 0; i < point_traits<point_type>::dim; ++i)
01233                     d += p.nth(i) * p.nth(i);
01234                   if (d > value_)
01235                     value_ = d;
01236                 }
01237             value_ /= 2;
01238             value_ = ntg::max(value_, last);
01239             value_ = ntg::max(value_, rhs.getValue());
01240           };
01241 
01249         bool less_impl(const lambda_type &lambda) const
01250           {
01251             return value_ < lambda;
01252           };
01253 
01261         bool ne_impl(const lambda_type &lambda) const
01262           {
01263             return lambda != value_;
01264           };
01265 
01266       protected:
01267         value_type      value_; 
01268         pts_type                pts_; 
01269       };
01270 
01271 
01272 
01273       /*-----------*
01274         |   dist    |
01275         *-----------*/
01281       template <class I, class Exact = mlc::final>
01282       class dist_type:
01283         public attribute<mlc_2_exact_vt_type(dist_type, I, Exact)>
01284       {
01285       public:
01286         typedef dist_type<I, Exact>                     self_type; 
01287         attr_type_decl(self_type);
01288         typedef abstract::image<mlc_exact_type(I)>      im_type; 
01289         typedef oln_point_type(im_type)                 point_type; 
01290         typedef oln_dpoint_type(im_type)                        dpoint_type; 
01291 
01298         dist_type()
01299           {
01300           };
01301 
01307         dist_type(const im_type&,
01308                   const point_type &p,
01309                   const env_type &):
01310           value_(ntg_zero_val(value_type)),
01311           center_(p)
01312           {
01313           };
01314 
01321         const value_type &getValue() const
01322           {
01323             mlc_dispatch(getValue)();
01324           };
01325 
01331         dist_type(const lambda_type lambda): value_(lambda)
01332           {
01333           };
01334 
01341         const point_type &getCenter() const
01342           {
01343             mlc_dispatch(getCenter)();
01344           };
01345 
01346         // impl
01355         const point_type &getCenter_impl() const
01356           {
01357             return center_;
01358           };
01359 
01368         const value_type &getValue_impl() const
01369           {
01370             return value_;
01371           };
01372 
01380         void pe_impl(const dist_type &rhs)
01381           {
01382             value_type  last = value_;
01383             dpoint_type p = center_ - rhs.getCenter();
01384 
01385             value_ = ntg_zero_val(value_type);
01386             for (int i = 0; i < point_traits<point_type>::dim; ++i)
01387               value_ += p.nth(i) * p.nth(i);
01388             value_ = sqrt(value_);
01389             value_ = ntg::max(value_, last);
01390             value_ = ntg::max(value_, rhs.getValue());
01391           };
01392 
01400         bool less_impl(const lambda_type &lambda) const
01401           {
01402             return value_ < lambda;
01403           };
01404 
01412         bool ne_impl(const lambda_type &lambda) const
01413           {
01414             return value_ != lambda;
01415           };
01416 
01417       protected:
01418         value_type value_; 
01419         point_type center_; 
01420 
01421       };
01422 
01423 
01424 
01425       /*-----------*
01426         |  cube   |
01427         *-----------*/
01433       template <class I, class Exact = mlc::final>
01434       class cube_type:
01435         public attribute<mlc_2_exact_vt_type(cube_type, I, Exact)>
01436       {
01437       public:
01438         typedef cube_type<I, Exact>                     self_type; 
01439         attr_type_decl(self_type);
01440         typedef abstract::image<mlc_exact_type(I)>      im_type; 
01441         typedef oln_point_type(im_type)                 point_type; 
01442         typedef oln_dpoint_type(im_type)                        dpoint_type; 
01443 
01444         enum {dim = point_traits<point_type>::dim};
01445 
01452         cube_type()
01453           {
01454           }
01455 
01461         cube_type(const lambda_type &lambda):
01462           mins_(dim),
01463           maxs_(dim),
01464           value_(lambda)
01465           {
01466             for (int i = 0; i < point_traits<point_type>::dim; ++i)
01467               {
01468                 maxs_[i] = lambda;
01469                 mins_[i] = ntg_zero_val(coord);
01470               }
01471           };
01472 
01478         cube_type(const im_type&,
01479                   const point_type &p,
01480                   const env_type &):
01481           mins_(dim), maxs_(dim), value_(ntg_zero_val(value_type))
01482           {
01483             for (int i = 0; i < dim; ++i)
01484               mins_[i] = maxs_[i] = p.nth(i);
01485           }
01486 
01495         int getMin(int i) const
01496           {
01497             mlc_dispatch(getMin)(i);
01498           };
01499 
01508         int getMax(int i) const
01509           {
01510             mlc_dispatch(getMax)(i);
01511           };
01512 
01513         // impl
01522         int getMin_impl(int i) const
01523           {
01524             precondition(i < dim);
01525             return mins_[i];
01526           };
01527 
01536         int getMax_impl(int i) const
01537           {
01538             precondition(i < dim);
01539             return maxs_[i];
01540           };
01541 
01549         void pe_impl(const cube_type &rhs)
01550           {
01551             for (int i = 0; i < dim; ++i)
01552               {
01553                 mins_[i] = ntg::min(mins_[i], rhs.getMin(i));
01554                 maxs_[i] = ntg::max(maxs_[i], rhs.getMax(i));
01555               }
01556             value_ = maxs_[0] - mins_[0];
01557             for (int i = 1; i < dim; ++i)
01558               if (value_ < value_type(maxs_[i] - mins_[i]))
01559                 value_ = maxs_[i] - mins_[i];
01560           }
01561 
01569         bool less_impl(const lambda_type &lambda) const
01570           {
01571             return value_ < lambda;
01572           }
01573 
01581         bool ne_impl(const lambda_type &lambda) const
01582           {
01583             return value_ != lambda;
01584           };
01585 
01586       protected:
01587         std::vector<coord>      mins_;
01588         std::vector<coord>      maxs_;
01589         value_type              value_;
01590       };
01591 
01592 
01593 
01594       /*------*
01595         | box |
01596         *-----*/
01602       template <class I, class Exact = mlc::final>
01603       class box_type:
01604         public attribute<mlc_2_exact_vt_type(box_type, I, Exact)>
01605       {
01606       public:
01607         typedef box_type<I, Exact>                      self_type; 
01608         attr_type_decl(self_type);
01609         typedef abstract::image<mlc_exact_type(I)>      im_type; 
01610         typedef oln_point_type(im_type)                 point_type; 
01611         typedef oln_dpoint_type(im_type)                        dpoint_type; 
01612         enum {dim = point_traits<point_type>::dim };
01613 
01619         box_type(const lambda_type &lambda): maxs_(dim), mins_(dim)
01620           {
01621             for (int i = 0; i < dim; ++i)
01622               {
01623                 mins_[i] = ntg_zero_val(value_type);
01624                 maxs_[i] = lambda[i];
01625               }
01626           };
01627 
01634         box_type()
01635           {
01636           };
01637 
01643         box_type(const im_type&, const point_type &p, const env_type &): maxs_(dim), mins_(dim)
01644           {
01645             for (int i = 0; i < dim; ++i)
01646               mins_[i] = maxs_[i] = p.nth(i);
01647           };
01648 
01657         value_type getMin(int i) const
01658           {
01659             mlc_dispatch(getMin)(i);
01660           };
01661 
01662 
01671         value_type getMax(int i) const
01672           {
01673             mlc_dispatch(getMax)(i);
01674           };
01675 
01676         // impl
01685         value_type getMin_impl(int i) const
01686           {
01687             precondition(i < point_traits<point_type>::dim);
01688             return mins_[i];
01689           };
01690 
01699         value_type getMax_impl(int i) const
01700           {
01701             precondition(i < point_traits<point_type>::dim);
01702             return maxs_[i];
01703           };
01704 
01712         void pe_impl(const box_type &rhs)
01713           {
01714             for (int i = 0; i < dim; ++i)
01715               {
01716                 mins_[i] = ntg::min(mins_[i], rhs.getMin(i));
01717                 maxs_[i] = ntg::max(maxs_[i], rhs.getMax(i));
01718               }
01719           }
01720 
01728         bool less_impl(const lambda_type &lambda) const
01729           {
01730             for (int i = 0; i < dim; ++i)
01731               if ((maxs_[i] - mins_[i]) >= lambda[i])
01732                 return false;
01733             return true;
01734           }
01735 
01743         bool ne_impl(const lambda_type &lambda) const
01744           {
01745             for (int i = 0; i < dim; ++i)
01746               if ((maxs_[i] - mins_[i]) == lambda[i])
01747                 return false;
01748             return true;
01749           };
01750 
01751       protected:
01752         std::vector<value_type> maxs_; 
01753         std::vector<value_type> mins_; 
01754       };
01755 
01756       /*-------------------------
01757         | traits specializations |
01758         \------------------------*/
01759 
01760 
01764       template <class T, class Exact>
01765       struct attr_traits<integral_type<T, Exact> >
01766       {
01767         typedef T               value_type; 
01768         typedef value_type      lambda_type; 
01769         typedef env::NullEnv    env_type; 
01770       };
01771 
01775       template <class T, class Exact>
01776       struct attr_traits<height_type<T, Exact> >
01777       {
01778         typedef T               value_type; 
01779         typedef value_type      lambda_type; 
01780         typedef env::NullEnv    env_type; 
01781       };
01782 
01786       template <class T, class Exact>
01787       struct attr_traits<card_type<T, Exact> >
01788       {
01789         typedef T               value_type; 
01790         typedef value_type      lambda_type; 
01791         typedef env::NullEnv    env_type; 
01792       };
01793 
01797       template <class I, class T, class Exact>
01798       struct attr_traits<card_full_type<I, T, Exact> >
01799       {
01800         typedef T                       value_type; 
01801         typedef value_type              lambda_type; 
01802         typedef env::OtherImageEnv<I>   env_type; 
01803       };
01804 
01808       template <class T, class Exact>
01809       struct attr_traits<maxvalue_type<T, Exact> >
01810       {
01811         typedef T               value_type; 
01812         typedef value_type      lambda_type; 
01813         typedef env::NullEnv    env_type; 
01814       };
01815 
01819       template <class T, class Exact>
01820       struct attr_traits<minvalue_type<T, Exact> >
01821       {
01822         typedef T               value_type; 
01823         typedef value_type      lambda_type; 
01824         typedef env::NullEnv    env_type; 
01825       };
01826 
01830       template <class I, class Exact>
01831       struct attr_traits<ball_type<I, Exact> >
01832       {
01833         typedef unsigned                        value_type; 
01834         typedef value_type                      lambda_type; 
01835         typedef oln::morpho::env::NullEnv       env_type; 
01836       };
01837 
01841       template <class I, class Exact>
01842       struct attr_traits<dist_type<I, Exact> >
01843       {
01844         typedef float                           value_type; 
01845         typedef value_type                      lambda_type; 
01846         typedef oln::morpho::env::NullEnv       env_type; 
01847       };
01848 
01852       template <class I, class Exact>
01853       struct attr_traits<cube_type<I, Exact> >
01854       {
01855         typedef unsigned                        value_type; 
01856         typedef value_type                      lambda_type; 
01857         typedef oln::morpho::env::NullEnv       env_type; 
01858       };
01859 
01863       template <class I, class Exact>
01864       struct attr_traits<box_type<I, Exact> >
01865       {
01866         typedef unsigned                                        value_type; 
01867         typedef ntg::vec<I::dim, value_type, mlc::final>        lambda_type; 
01868         typedef oln::morpho::env::NullEnv                       env_type; 
01869       };
01870 
01874       template <class Dad, class I, class Exact>
01875       struct attr_traits<other_image<Dad, I, Exact> >
01876       {
01877         //typedef typename change_exact<Dad, other_image<Dad, I, Exact> >::ret  super_type;
01878         typedef typename change_exact<Dad,
01879                                       typename mlc::exact_vt<other_image<Dad, I, Exact>,
01880                                                              Exact>::ret>::ret          super_type; 
01881         typedef attr_value_type(super_type)                                             value_type; 
01882         typedef attr_lambda_type(super_type)                                            lambda_type; 
01883         typedef oln::morpho::env::OtherImageEnv<I>                                      env_type; 
01884       };
01885 
01889       template <class I, class Exact>
01890       struct attr_traits<ball_parent_change<I, Exact> >
01891       {
01892         typedef unsigned                value_type; 
01893         typedef value_type              lambda_type; 
01894         typedef env::ParentEnv<I>       env_type; 
01895       };
01896 
01897       // traits for other_image derivation
01898 
01904       template <class NewExact, class OldExact, class T>
01905       struct change_exact<integral_type<T, OldExact>, NewExact>
01906       {
01907         typedef integral_type<T, NewExact>      ret;
01908       };
01909 
01910     }// !attr
01911   } // !morpho
01912 } 
01913 
01914   /*-----------*
01915     |  diamond  |
01916     *-----------*/
01917 
01918   // FIXME: to be written...
01919 
01920 
01921 #endif // !OLN_MORPHO_ATTRIBUTES
01922 
01923 

Generated on Thu Apr 15 20:13:06 2004 for Olena by doxygen 1.3.6-20040222