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, 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 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 # include <oln/morpho/abstract/attribute.hh>
00035 
00036 namespace oln {
00037   namespace morpho {
00040     namespace attr {
00043       namespace tools {
00044 
00049         template <class T>
00050         T diffabs(const T &v1, const T &v2)
00051         {
00052           return v1 > v2 ? v1 - v2 : v2 - v1;
00053         }
00054       } // !tools
00055 
00063       template <class In, class Exact>
00064       struct change_exact;
00065 
00066 
00067       /*-----------*
00068         |   card    |
00069         *-----------*/
00070 
00076       template <class T = unsigned, class Exact = mlc::final>
00077       class card_type:
00078         public abstract::attribute<mlc_2_exact_vt_type(card_type, T, Exact)>
00079       {
00080       public:
00081         typedef card_type<T, Exact>                     self_type; 
00082         attr_type_decl(self_type);
00083 
00090         card_type()
00091           {
00092           };
00093 
00097         card_type(const lambda_type &lambda): value_(lambda)
00098           {
00099           };
00100 
00106         template <class I>
00107           card_type(const oln::abstract::image<I>&,
00108                     const oln_point_type(I)&,
00109                     const env_type&):
00110           value_(ntg_unit_val(value_type))
00111           {
00112           }
00113 
00114 
00122         void pe_impl(const self_type &rhs)
00123           {
00124             value_ += rhs.value_;
00125           };
00126 
00134         bool less_impl(const lambda_type &lambda) const
00135           {
00136             return value_ < lambda;
00137           };
00138 
00146         bool ne_impl(const lambda_type &lambda) const
00147           {
00148             return lambda != value_;
00149           };
00150 
00158         const lambda_type &toLambda_impl() const
00159         {
00160           return value_;
00161         };
00162 
00163       protected:
00164         value_type value_; 
00165       };
00166 
00167       /*-------------------------------*
00168         | card with info on other image |
00169         *------------------------------*/
00170       template <class I, class T = unsigned, class Exact = mlc::final>
00171       class card_full_type: public card_type<T,
00172                                              typename mlc::exact_vt<card_full_type<I,
00173                                                                                    T,
00174                                                                                    Exact>,
00175                                                                     Exact>::ret>
00176       {
00177       public:
00178         typedef card_full_type<I, T, Exact>                     self_type; 
00179         attr_type_decl(self_type);
00180         typedef card_type<T, exact_type>                        super_type; 
00181 
00188         card_full_type(): super_type()
00189           {
00190           };
00191 
00195         card_full_type(const lambda_type &lambda): super_type(lambda)
00196           {
00197           };
00198 
00204         template <class I2>
00205           card_full_type(const oln::abstract::image<I2> &im,
00206                          const oln_point_type(I2) &p,
00207                          const env_type &env): super_type(im, p, env)
00208           {
00209           }
00210       };
00211 
00212       /*-----------*
00213         |  volume   |
00214         *-----------*/
00221       template <class I, class Exact = mlc::final>
00222       class volume_type:
00223         public abstract::attribute<mlc_2_exact_vt_type(volume_type, I, Exact)>
00224       {
00225       public:
00226         typedef volume_type<I, Exact>                   self_type; 
00227         attr_type_decl(self_type);
00228 
00235         volume_type()
00236           {
00237           };
00238 
00242         volume_type(const lambda_type &lambda): value_(lambda)
00243           {
00244           };
00245 
00249         template <class J>
00250           volume_type(const oln::abstract::image<J> &,
00251                       const oln_point_type(J) &p,
00252                       const env_type &e) :
00253           //      reflevel_(e.getImage()[p]),
00254           reflevel_(e.getImage()[p]),
00255           area_(ntg_unit_val(value_type)),
00256           value_(ntg_unit_val(value_type))
00257           {
00258           }
00259 
00260         // interface part
00267         const value_type &getValue() const
00268           {
00269             mlc_dispatch(getValue)();
00270           };
00271 
00277         const value_type &getReflevel() const
00278           {
00279             mlc_dispatch(getReflevel)();
00280           };
00281 
00287         const value_type &getArea() const
00288           {
00289             mlc_dispatch(getArea)();
00290           };
00291 
00292         // impl part
00301         const value_type &getValue_impl() const
00302           {
00303             return value_;
00304           };
00305 
00314         const value_type &getReflevel_impl() const
00315           {
00316             return reflevel_;
00317           };
00318 
00327         const value_type &getArea_impl() const
00328           {
00329             return area_;
00330           };
00331 
00339         void pe_impl(const volume_type &rhs)
00340           {
00341             value_ += rhs.getValue() + area_ * tools::diffabs(reflevel_, rhs.getReflevel());
00342             area_ += rhs.getArea();
00343           };
00344 
00352         bool less_impl(const lambda_type &lambda) const
00353           {
00354             return value_ < lambda;
00355           };
00356 
00364         bool ne_impl(const lambda_type &lambda) const
00365           {
00366             return lambda != value_;
00367           };
00368 
00369       protected:
00370         value_type reflevel_; 
00371         value_type area_; 
00372         value_type value_; 
00373       };
00374 
00375 
00376       /*--------------*
00377         |  integral   |
00378         *------------*/
00379 
00386       template <class T = unsigned, class Exact = mlc::final>
00387       class integral_type:
00388         public abstract::attribute<mlc_2_exact_vt_type(integral_type, T, Exact)>
00389       {
00390       public:
00391         typedef integral_type<T, Exact>                 self_type; 
00392         attr_type_decl(self_type);
00393 
00400         integral_type()
00401           {
00402           };
00403 
00407         integral_type(const lambda_type &lambda): value_(lambda)
00408           {
00409           };
00410 
00414         template <class I>
00415           integral_type(const oln::abstract::image<I> &input,
00416                         const oln_point_type(I) &p,
00417                         const env_type &) :
00418           value_(input[p])
00419           {
00420           }
00421 
00422         // interface part
00429         const value_type &getValue() const
00430           {
00431             mlc_dispatch(getValue)();
00432           };
00433 
00434         // impl part
00443         const value_type &getValue_impl() const
00444           {
00445             return value_;
00446           };
00447 
00448 
00456         void pe_impl(const self_type &rhs)
00457           {
00458             value_ += rhs.getValue();
00459           };
00460 
00468         bool less_impl(const lambda_type &lambda) const
00469           {
00470             return value_ < lambda;
00471           };
00472 
00480         bool ne_impl(const lambda_type &lambda) const
00481           {
00482             return lambda != value_;
00483           };
00484 
00485       protected:
00486         value_type value_; 
00487       };
00488 
00489       /*-------------------*
00490         | other image_type |
00491         ------------------*/
00500       template <class Dad, class I, class Exact = mlc::final>
00501       class other_image:
00502         public change_exact<Dad, typename mlc::exact_vt<other_image<Dad, I, Exact>, Exact>::ret >::ret
00503       {
00504       public:
00505         typedef other_image<Dad, I,  Exact>                                             self_type; /*< Self type of the class.*/
00506         typedef typename oln::abstract::image<mlc_exact_type(I)>                                im_type; /*< Type of substituted image.*/
00507         attr_type_decl(self_type);
00508         typedef typename change_exact<Dad,
00509                                       typename mlc::exact_vt<other_image<Dad, I, Exact>,
00510                                                              Exact>::ret >::ret         super_type; /*< Mother class type.*/
00511 
00517         other_image(): super_type()
00518         {
00519         };
00520 
00526         other_image(const lambda_type &lambda): super_type(lambda)
00527         {
00528         };
00529 
00536         template <typename IM>
00537         other_image(const oln::abstract::image<IM> &,
00538                     const oln_point_type(I) &p,
00539                     const env_type & e): super_type(e.getImage(), p, e)
00540         {
00541         }
00542       };
00543 
00544       /*----------------------*
00545         | ball_parent_change |
00546         *--------------------*/
00555       template <class I, class Exact = mlc::final>
00556       class ball_parent_change:
00557         public abstract::attribute<mlc_2_exact_vt_type(ball_parent_change, I, Exact)>
00558       {
00559       public:
00560         typedef ball_parent_change<I,  Exact>                   self_type; /*< Self type of the class.*/
00561         typedef typename oln::abstract::image<mlc_exact_type(I)>        im_type; /*< Type of substituted image.*/
00562         attr_type_decl(self_type);
00563         typedef oln_value_type(I)                               pts_type; 
00564         typedef typename pts_type::const_iterator               cst_iter_type; 
00565         typedef typename pts_type::value_type                   point_type; 
00566         typedef oln_dpoint_type(point_type)     dpoint_type; 
00567 
00573         ball_parent_change(): value_(ntg_zero_val(value_type)), points_()
00574         {
00575         };
00576 
00582         ball_parent_change(const lambda_type &lambda): value_(lambda), points_()
00583         {
00584         };
00585 
00592         template <typename IM>
00593         ball_parent_change(const oln::abstract::image<IM> &,
00594                            const oln_point_type(IM) &p,
00595                            const env_type &e): points_()//: super_type(/*e.getImage(), */e.getPoint(p), e)
00596         {
00597           std::copy(e.getParent()[p].begin(),
00598                     e.getParent()[p].end(),
00599                     std::back_inserter(points_));
00600         }
00601 
00608         const value_type &getValue() const
00609           {
00610             mlc_dispatch(getValue)();
00611           };
00612 
00613 
00620         const pts_type &getPts() const
00621           {
00622             mlc_dispatch(getPts)();
00623           };
00624 
00625         // impl
00634         const value_type &getValue_impl() const
00635           {
00636             return value_;
00637           };
00638 
00647         const pts_type &getPts_impl() const
00648           {
00649             return points_;
00650           };
00651 
00659         void pe_impl(const self_type &rhs)
00660           {
00661             precondition(points_.size() < (128 * 128 * 128 + 1));
00662             std::copy(rhs.getPts().begin(),
00663                       rhs.getPts().end(),
00664                       std::back_inserter(points_));
00665             compute_value();
00666             value_ = ntg::max(value_, rhs.getValue());
00667           };
00668 
00676         bool less_impl(const lambda_type &lambda) const
00677           {
00678             return value_ < lambda;
00679           };
00680 
00688         bool ne_impl(const lambda_type &lambda) const
00689           {
00690             return lambda != value_;
00691           };
00692 
00693       protected:
00694         void compute_value()
00695           {
00696             value_type  last = value_;
00697             value_ = ntg_zero_val(value_type);
00698             for (cst_iter_type p1 = points_.begin(); p1 != points_.end(); ++p1)
00699               for (cst_iter_type p2 = points_.begin(); p2 != points_.end(); ++p2)
00700                 {
00701                   unsigned d = 0;
00702                   dpoint_type   p = *p1 - *p2;
00703                   for (int i = 0; i < point_traits<point_type>::dim; ++i)
00704                     d += p.nth(i) * p.nth(i);
00705                   if (d > value_)
00706                     value_ = d;
00707                 }
00708             value_ /= 2;
00709             value_ = ntg::max(value_, last);
00710           }
00711 
00712         value_type      value_;
00713         pts_type        points_;
00714       };
00715 
00716       /*-----------*
00717         |  height   |
00718         *-----------*/
00722       template <class T = unsigned, class Exact = mlc::final>
00723       class height_type:
00724         public abstract::attribute<mlc_2_exact_vt_type(height_type, T, Exact)>
00725       {
00726       public:
00727         typedef height_type<T, Exact>                   self_type;
00728         attr_type_decl(self_type);
00729 
00736         height_type()
00737           {
00738           };
00739 
00743         height_type(const lambda_type &lambda):
00744           value_(lambda),
00745           min_(ntg_zero_val(value_type)),
00746           max_(lambda)
00747           {
00748           };
00749 
00753         template <class I>
00754           height_type(const oln::abstract::image<I> &input,
00755                       const oln_point_type(I) &p,
00756                       const env_type&):
00757           value_(ntg_zero_val(value_type)),
00758           min_(input[p]),
00759           max_(input[p])
00760           {
00761           }
00762 
00769         const value_type &getMin() const
00770           {
00771             mlc_dispatch(getMin)();
00772           };
00773 
00780         const value_type &getMax() const
00781           {
00782             mlc_dispatch(getMax)();
00783           };
00784 
00785         // impl part
00794         const value_type &getMin_impl() const
00795           {
00796             return min_;
00797           };
00798 
00807         const value_type &getMax_impl() const
00808           {
00809             return max_;
00810           };
00811 
00819         void pe_impl(const height_type &rhs)
00820           {
00821             min_ = ntg::min(min_, rhs.getMin());
00822             max_ = ntg::max(max_, rhs.getMax());
00823             value_ = max_ - min_;
00824           };
00825 
00833         bool less_impl(const lambda_type &lambda) const
00834           {
00835             return value_ < lambda;
00836           };
00837 
00845         bool ne_impl(const lambda_type &lambda) const
00846           {
00847             return lambda != value_;
00848           };
00849 
00850       protected:
00851         value_type      value_; 
00852         value_type      min_; 
00853         value_type      max_; 
00854       };
00855 
00856 
00857       /*-----------*
00858         | maxvalue  |
00859         *-----------*/
00865       template <class T = unsigned, class Exact = mlc::final>
00866       class maxvalue_type:
00867         public abstract::attribute<mlc_2_exact_vt_type(maxvalue_type, T, Exact)>
00868       {
00869       public:
00870         typedef maxvalue_type<T, Exact>                 self_type; 
00871         attr_type_decl(self_type);
00872 
00879         maxvalue_type()
00880           {
00881           };
00882 
00888         maxvalue_type(const lambda_type &lambda): value_(lambda)
00889           {
00890           };
00891 
00900         template <class I>
00901           maxvalue_type(const oln::abstract::image<I> &input,
00902                         const oln_point_type(I) &p,
00903                         const env_type &):
00904           value_(input[p])
00905           {
00906           }
00907 
00914         const value_type &getValue() const
00915           {
00916             mlc_dispatch(getValue)();
00917           };
00918 
00927         const value_type &getValue_impl() const
00928           {
00929             return value_;
00930           };
00931 
00939         void pe_impl(const maxvalue_type &rhs)
00940           {
00941             value_ = ntg::max(value_, rhs.getValue());
00942           };
00943 
00951         bool less_impl(const lambda_type &lambda) const
00952           {
00953             return value_ < lambda;
00954           };
00955 
00963         bool ne_impl(const lambda_type &lambda) const
00964           {
00965             return lambda != value_;
00966           };
00967 
00968       protected:
00969         value_type value_; 
00970       };
00971 
00972 
00973       /*-----------*
00974         | minvalue  |
00975         *-----------*/
00981       template <class T = unsigned, class Exact = mlc::final>
00982       class minvalue_type:
00983         public abstract::attribute<mlc_2_exact_vt_type(minvalue_type, T, Exact)>
00984       {
00985       public:
00986         typedef minvalue_type<T, Exact>                 self_type;
00987         attr_type_decl(self_type);
00988 
00995         minvalue_type()
00996           {
00997           };
00998 
01004         minvalue_type(const lambda_type &lambda): value_(lambda)
01005           {
01006           };
01007 
01016         template <class I>
01017           minvalue_type(const oln::abstract::image<I> &input,
01018                         const oln_point_type(I) &p,
01019                         const env_type &) :
01020           value_(input[p])
01021           {
01022           }
01023 
01030         const value_type &getValue() const
01031           {
01032             mlc_dispatch(getValue)();
01033           };
01034 
01043         const value_type &getValue_impl() const
01044           {
01045             return value_;
01046           };
01047 
01055         void pe_impl(const minvalue_type &rhs)
01056           {
01057             value_ = ntg::min(value_, rhs.getValue());
01058           };
01059 
01067         bool less_impl(const lambda_type &lambda) const
01068           {
01069             return value_ > lambda;
01070           };
01071 
01079         bool ne_impl(const lambda_type &lambda) const
01080           {
01081             return lambda != value_;
01082           };
01083 
01084       protected:
01085         value_type value_; 
01086       };
01087 
01088 
01089       /*-----------*
01090         |   ball    |
01091         *-----------*/
01097       template <class I, class Exact = mlc::final>
01098       class ball_type:
01099         public abstract::attribute<mlc_2_exact_vt_type(ball_type, I, Exact)>
01100       {
01101       public:
01102         typedef ball_type<I, Exact>                     self_type; 
01103         attr_type_decl(self_type);
01104         typedef oln::abstract::image<mlc_exact_type(I)> im_type; 
01105         typedef oln_point_type(im_type)                 point_type; 
01106         typedef oln_dpoint_type(im_type)                        dpoint_type; 
01107         typedef std::vector<point_type>                 pts_type; 
01108         typedef typename pts_type::const_iterator               cst_iter_type; 
01109 
01116         ball_type()
01117           {
01118           };
01119 
01125         ball_type(const lambda_type &lambda): value_(lambda), pts_()
01126           {
01127           };
01128 
01129 
01135         ball_type(const im_type&, const point_type &p, const env_type &) :
01136           value_(ntg_zero_val(value_type)), pts_()
01137 
01138           {
01139             pts_.push_back(p);
01140           };
01141 
01148         const value_type &getValue() const
01149           {
01150             mlc_dispatch(getValue)();
01151           };
01152 
01153 
01160         const pts_type &getPts() const
01161           {
01162             mlc_dispatch(getPts)();
01163           };
01164 
01165         // impl
01174         const value_type &getValue_impl() const
01175           {
01176             return value_;
01177           };
01178 
01187         const pts_type &getPts_impl() const
01188           {
01189             return pts_;
01190           };
01191 
01199         void pe_impl(const ball_type &rhs)
01200           {
01201             value_type  last = value_;
01202             std::copy(rhs.getPts().begin(),
01203                       rhs.getPts().end(),
01204                       std::back_inserter(pts_));
01205             value_ = ntg_zero_val(value_type);
01206             for (cst_iter_type p1 = pts_.begin(); p1 != pts_.end(); ++p1)
01207               for (cst_iter_type p2 = pts_.begin(); p2 != pts_.end(); ++p2)
01208                 {
01209                   unsigned d = 0;
01210                   dpoint_type   p = *p1 - *p2;
01211                   for (int i = 0; i < point_traits<point_type>::dim; ++i)
01212                     d += p.nth(i) * p.nth(i);
01213                   if (d > value_)
01214                     value_ = d;
01215                 }
01216             value_ /= 2;
01217             value_ = ntg::max(value_, last);
01218             value_ = ntg::max(value_, rhs.getValue());
01219           };
01220 
01228         bool less_impl(const lambda_type &lambda) const
01229           {
01230             return value_ < lambda;
01231           };
01232 
01240         bool ne_impl(const lambda_type &lambda) const
01241           {
01242             return lambda != value_;
01243           };
01244 
01245       protected:
01246         value_type      value_; 
01247         pts_type                pts_; 
01248       };
01249 
01250 
01251 
01252       /*-----------*
01253         |   dist    |
01254         *-----------*/
01260       template <class I, class Exact = mlc::final>
01261       class dist_type:
01262         public abstract::attribute<mlc_2_exact_vt_type(dist_type, I, Exact)>
01263       {
01264       public:
01265         typedef dist_type<I, Exact>                     self_type; 
01266         attr_type_decl(self_type);
01267         typedef oln::abstract::image<mlc_exact_type(I)> im_type; 
01268         typedef oln_point_type(im_type)                 point_type; 
01269         typedef oln_dpoint_type(im_type)                        dpoint_type; 
01270 
01277         dist_type()
01278           {
01279           };
01280 
01286         dist_type(const im_type&,
01287                   const point_type &p,
01288                   const env_type &):
01289           value_(ntg_zero_val(value_type)),
01290           center_(p)
01291           {
01292           };
01293 
01300         const value_type &getValue() const
01301           {
01302             mlc_dispatch(getValue)();
01303           };
01304 
01310         dist_type(const lambda_type lambda): value_(lambda)
01311           {
01312           };
01313 
01320         const point_type &getCenter() const
01321           {
01322             mlc_dispatch(getCenter)();
01323           };
01324 
01325         // impl
01334         const point_type &getCenter_impl() const
01335           {
01336             return center_;
01337           };
01338 
01347         const value_type &getValue_impl() const
01348           {
01349             return value_;
01350           };
01351 
01359         void pe_impl(const dist_type &rhs)
01360           {
01361             value_type  last = value_;
01362             dpoint_type p = center_ - rhs.getCenter();
01363 
01364             value_ = ntg_zero_val(value_type);
01365             for (int i = 0; i < point_traits<point_type>::dim; ++i)
01366               value_ += p.nth(i) * p.nth(i);
01367             value_ = sqrt(value_);
01368             value_ = ntg::max(value_, last);
01369             value_ = ntg::max(value_, rhs.getValue());
01370           };
01371 
01379         bool less_impl(const lambda_type &lambda) const
01380           {
01381             return value_ < lambda;
01382           };
01383 
01391         bool ne_impl(const lambda_type &lambda) const
01392           {
01393             return value_ != lambda;
01394           };
01395 
01396       protected:
01397         value_type value_; 
01398         point_type center_; 
01399 
01400       };
01401 
01402 
01403 
01404       /*-----------*
01405         |  cube   |
01406         *-----------*/
01412       template <class I, class Exact = mlc::final>
01413       class cube_type:
01414         public abstract::attribute<mlc_2_exact_vt_type(cube_type, I, Exact)>
01415       {
01416       public:
01417         typedef cube_type<I, Exact>                     self_type; 
01418         attr_type_decl(self_type);
01419         typedef oln::abstract::image<mlc_exact_type(I)> im_type; 
01420         typedef oln_point_type(im_type)                 point_type; 
01421         typedef oln_dpoint_type(im_type)                        dpoint_type; 
01422 
01423         enum {dim = point_traits<point_type>::dim};
01424 
01431         cube_type()
01432           {
01433           }
01434 
01440         cube_type(const lambda_type &lambda):
01441           mins_(dim),
01442           maxs_(dim),
01443           value_(lambda)
01444           {
01445             for (int i = 0; i < point_traits<point_type>::dim; ++i)
01446               {
01447                 maxs_[i] = lambda;
01448                 mins_[i] = ntg_zero_val(coord);
01449               }
01450           };
01451 
01457         cube_type(const im_type&,
01458                   const point_type &p,
01459                   const env_type &):
01460           mins_(dim), maxs_(dim), value_(ntg_zero_val(value_type))
01461           {
01462             for (int i = 0; i < dim; ++i)
01463               mins_[i] = maxs_[i] = p.nth(i);
01464           }
01465 
01474         int getMin(int i) const
01475           {
01476             mlc_dispatch(getMin)(i);
01477           };
01478 
01487         int getMax(int i) const
01488           {
01489             mlc_dispatch(getMax)(i);
01490           };
01491 
01492         // impl
01501         int getMin_impl(int i) const
01502           {
01503             precondition(i < dim);
01504             return mins_[i];
01505           };
01506 
01515         int getMax_impl(int i) const
01516           {
01517             precondition(i < dim);
01518             return maxs_[i];
01519           };
01520 
01528         void pe_impl(const cube_type &rhs)
01529           {
01530             for (int i = 0; i < dim; ++i)
01531               {
01532                 mins_[i] = ntg::min(mins_[i], rhs.getMin(i));
01533                 maxs_[i] = ntg::max(maxs_[i], rhs.getMax(i));
01534               }
01535             value_ = maxs_[0] - mins_[0];
01536             for (int i = 1; i < dim; ++i)
01537               if (value_ < value_type(maxs_[i] - mins_[i]))
01538                 value_ = maxs_[i] - mins_[i];
01539           }
01540 
01548         bool less_impl(const lambda_type &lambda) const
01549           {
01550             return value_ < lambda;
01551           }
01552 
01560         bool ne_impl(const lambda_type &lambda) const
01561           {
01562             return value_ != lambda;
01563           };
01564 
01565       protected:
01566         std::vector<coord>      mins_;
01567         std::vector<coord>      maxs_;
01568         value_type              value_;
01569       };
01570 
01571 
01572 
01573       /*------*
01574         | box |
01575         *-----*/
01581       template <class I, class Exact = mlc::final>
01582       class box_type:
01583         public abstract::attribute<mlc_2_exact_vt_type(box_type, I, Exact)>
01584       {
01585       public:
01586         typedef box_type<I, Exact>                      self_type; 
01587         attr_type_decl(self_type);
01588         typedef oln::abstract::image<mlc_exact_type(I)> im_type; 
01589         typedef oln_point_type(im_type)                 point_type; 
01590         typedef oln_dpoint_type(im_type)                        dpoint_type; 
01591         enum {dim = point_traits<point_type>::dim };
01592 
01598         box_type(const lambda_type &lambda): maxs_(dim), mins_(dim)
01599           {
01600             for (int i = 0; i < dim; ++i)
01601               {
01602                 mins_[i] = ntg_zero_val(value_type);
01603                 maxs_[i] = lambda[i];
01604               }
01605           };
01606 
01613         box_type()
01614           {
01615           };
01616 
01622         box_type(const im_type&, const point_type &p, const env_type &): maxs_(dim), mins_(dim)
01623           {
01624             for (int i = 0; i < dim; ++i)
01625               mins_[i] = maxs_[i] = p.nth(i);
01626           };
01627 
01636         value_type getMin(int i) const
01637           {
01638             mlc_dispatch(getMin)(i);
01639           };
01640 
01641 
01650         value_type getMax(int i) const
01651           {
01652             mlc_dispatch(getMax)(i);
01653           };
01654 
01655         // impl
01664         value_type getMin_impl(int i) const
01665           {
01666             precondition(i < point_traits<point_type>::dim);
01667             return mins_[i];
01668           };
01669 
01678         value_type getMax_impl(int i) const
01679           {
01680             precondition(i < point_traits<point_type>::dim);
01681             return maxs_[i];
01682           };
01683 
01691         void pe_impl(const box_type &rhs)
01692           {
01693             for (int i = 0; i < dim; ++i)
01694               {
01695                 mins_[i] = ntg::min(mins_[i], rhs.getMin(i));
01696                 maxs_[i] = ntg::max(maxs_[i], rhs.getMax(i));
01697               }
01698           }
01699 
01707         bool less_impl(const lambda_type &lambda) const
01708           {
01709             for (int i = 0; i < dim; ++i)
01710               if ((maxs_[i] - mins_[i]) >= lambda[i])
01711                 return false;
01712             return true;
01713           }
01714 
01722         bool ne_impl(const lambda_type &lambda) const
01723           {
01724             for (int i = 0; i < dim; ++i)
01725               if ((maxs_[i] - mins_[i]) == lambda[i])
01726                 return false;
01727             return true;
01728           };
01729 
01730       protected:
01731         std::vector<value_type> maxs_; 
01732         std::vector<value_type> mins_; 
01733       };
01734 
01735       /*-------------------------
01736         | traits specializations |
01737         \------------------------*/
01738 
01739 
01743       template <class T, class Exact>
01744       struct attr_traits<integral_type<T, Exact> >
01745       {
01746         typedef T               value_type; 
01747         typedef value_type      lambda_type; 
01748         typedef env::NullEnv    env_type; 
01749       };
01750 
01754       template <class T, class Exact>
01755       struct attr_traits<height_type<T, Exact> >
01756       {
01757         typedef T               value_type; 
01758         typedef value_type      lambda_type; 
01759         typedef env::NullEnv    env_type; 
01760       };
01761 
01765       template <class T, class Exact>
01766       struct attr_traits<card_type<T, Exact> >
01767       {
01768         typedef T               value_type; 
01769         typedef value_type      lambda_type; 
01770         typedef env::NullEnv    env_type; 
01771       };
01772 
01776       template <class I, class T, class Exact>
01777       struct attr_traits<card_full_type<I, T, Exact> >
01778       {
01779         typedef T                       value_type; 
01780         typedef value_type              lambda_type; 
01781         typedef env::OtherImageEnv<I>   env_type; 
01782       };
01783 
01787       template <class T, class Exact>
01788       struct attr_traits<maxvalue_type<T, Exact> >
01789       {
01790         typedef T               value_type; 
01791         typedef value_type      lambda_type; 
01792         typedef env::NullEnv    env_type; 
01793       };
01794 
01798       template <class T, class Exact>
01799       struct attr_traits<minvalue_type<T, Exact> >
01800       {
01801         typedef T               value_type; 
01802         typedef value_type      lambda_type; 
01803         typedef env::NullEnv    env_type; 
01804       };
01805 
01809       template <class I, class Exact>
01810       struct attr_traits<ball_type<I, Exact> >
01811       {
01812         typedef unsigned                        value_type; 
01813         typedef value_type                      lambda_type; 
01814         typedef oln::morpho::env::NullEnv       env_type; 
01815       };
01816 
01820       template <class I, class Exact>
01821       struct attr_traits<dist_type<I, Exact> >
01822       {
01823         typedef float                           value_type; 
01824         typedef value_type                      lambda_type; 
01825         typedef oln::morpho::env::NullEnv       env_type; 
01826       };
01827 
01831       template <class I, class Exact>
01832       struct attr_traits<cube_type<I, Exact> >
01833       {
01834         typedef unsigned                        value_type; 
01835         typedef value_type                      lambda_type; 
01836         typedef oln::morpho::env::NullEnv       env_type; 
01837       };
01838 
01842       template <class I, class Exact>
01843       struct attr_traits<box_type<I, Exact> >
01844       {
01845         typedef unsigned                                        value_type; 
01846         typedef ntg::vec<I::dim, value_type, mlc::final>        lambda_type; 
01847         typedef oln::morpho::env::NullEnv                       env_type; 
01848       };
01849 
01853       template <class Dad, class I, class Exact>
01854       struct attr_traits<other_image<Dad, I, Exact> >
01855       {
01856         //typedef typename change_exact<Dad, other_image<Dad, I, Exact> >::ret  super_type;
01857         typedef typename change_exact<Dad,
01858                                       typename mlc::exact_vt<other_image<Dad, I, Exact>,
01859                                                              Exact>::ret>::ret          super_type; 
01860         typedef attr_value_type(super_type)                                             value_type; 
01861         typedef attr_lambda_type(super_type)                                            lambda_type; 
01862         typedef oln::morpho::env::OtherImageEnv<I>                                      env_type; 
01863       };
01864 
01868       template <class I, class Exact>
01869       struct attr_traits<ball_parent_change<I, Exact> >
01870       {
01871         typedef unsigned                value_type; 
01872         typedef value_type              lambda_type; 
01873         typedef env::ParentEnv<I>       env_type; 
01874       };
01875 
01876       // traits for other_image derivation
01877 
01883       template <class NewExact, class OldExact, class T>
01884       struct change_exact<integral_type<T, OldExact>, NewExact>
01885       {
01886         typedef integral_type<T, NewExact>      ret;
01887       };
01888 
01892       template <class I, class Exact>
01893       struct attr_traits<volume_type<I, Exact> >
01894       {
01895         typedef unsigned        value_type;
01896         typedef value_type      lambda_type;
01897         typedef env::OtherImageEnv<I>           env_type;
01898       };
01899     }// !attr
01900   } // !morpho
01901 } 
01902 
01903   /*-----------*
01904     |  diamond  |
01905     *-----------*/
01906 
01907   // FIXME: to be written...
01908 
01909 
01910 #endif // !OLN_MORPHO_ATTRIBUTES
01911 
01912 

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