• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

hexa.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_CORE_IMAGE_DMORPH_HEXA_HH
00027 # define MLN_CORE_IMAGE_DMORPH_HEXA_HH
00028 
00029 
00034 
00035 # include <mln/core/internal/image_domain_morpher.hh>
00036 # include <mln/core/alias/point2d_h.hh>
00037 # include <mln/core/alias/box2d_h.hh>
00038 # include <mln/core/image/dmorph/hexa_piter.hh>
00039 
00040 
00041 namespace mln
00042 {
00043 
00044   // Forward declaration.
00045   template <typename I> class hexa;
00046 
00047 
00048   namespace internal
00049   {
00051     template <typename I>
00052     struct data< hexa<I> >
00053     {
00054       data(I& ima, box2d_h b);
00055 
00056       I ima_;
00057       mln::box2d_h b_;
00058     };
00059 
00060   } // end of namespace mln::internal
00061 
00062 
00063   namespace trait
00064   {
00066     template <typename I>
00067     struct image_< hexa<I> > : default_image_morpher< I, mln_value(I),
00068                                                        hexa<I> >
00069     {
00070       //     private:
00071       //       typedef mln_trait_image_data(I) I_data_;
00072       //       typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_;
00073       //     public:
00074 
00075       typedef trait::image::category::domain_morpher category;
00076 
00077       typedef mln_trait_image_pw_io(I)      pw_io; // un-write when I const
00078       typedef mln_trait_image_dimension(I)  dimension;
00079 
00080       // Extended domain
00081       typedef mln_trait_image_ext_domain(I) ext_domain;  // have a border only if I does.
00082       typedef mln_trait_image_ext_value(I)  ext_value;
00083       typedef mln_trait_image_ext_io(I)     ext_io; // un-write when I const
00084 
00085       //       typedef mlc_if( I_data_are_linear_,
00086       //                      trait::data::stored, // if linear then just stored
00087       //                      I_data_ ) data;      // otherwise like I
00088     };
00089 
00090   } // end of namespace mln::trait
00091 
00092 
00115   template <typename I>
00116   struct hexa :
00117     public internal::image_domain_morpher< I, box2d_h, hexa<I> >
00118   {
00120     typedef hexa< tag::image_<I> > skeleton;
00121 
00123     typedef mln_value(I) value;
00124 
00126     typedef mln_lvalue(I) lvalue;
00127 
00129     typedef mln_rvalue(I) rvalue;
00130 
00132     typedef point2d_h psite;
00133 
00136     typedef hexa_fwd_piter_<box2d> fwd_piter;
00137 
00140     typedef hexa_bkd_piter_<box2d> bkd_piter;
00141 
00142 
00144     hexa();
00145 
00147     hexa(I& ima);
00148 
00150     void init_(I& ima);
00151 
00153     const box2d_h& domain() const;
00154 
00156     bool has(const psite& p) const;
00157 
00159     rvalue operator()(const point2d_h& p) const;
00160 
00162     lvalue operator()(const point2d_h& p);
00163   };
00164 
00165   template <typename I, typename J>
00166   void init_(tag::image_t, hexa<I>& target, const J& model);
00167 
00168 # ifndef MLN_INCLUDE_ONLY
00169 
00170 
00171   // init_
00172 
00173   template <typename I, typename J>
00174   inline
00175   void init_(tag::image_t, hexa<I>& target, const J& model)
00176   {
00177     I ima;
00178     init_(tag::image, ima, model);
00179     target.init_(ima);
00180   }
00181 
00182 
00183 
00184   // internal::data< hexa<I> >
00185 
00186   namespace internal
00187   {
00188 
00189     template <typename I>
00190     inline
00191     data< hexa<I> >::data(I& ima, box2d_h b)
00192       : ima_(ima),
00193         b_(b)
00194     {
00195     }
00196 
00197   } // end of namespace mln::internal
00198 
00199 
00200   template <typename I>
00201   inline
00202   void
00203   hexa<I>::init_(I& ima)
00204   {
00205     mln_precondition(! this->is_valid());
00206     box2d b_in = ima.bbox();
00207     box2d_h b = make::box2d_h(b_in.pmin()[0] * 2, b_in.pmin()[1],
00208                               b_in.pmax()[0] * 2, (b_in.pmax()[1] + 1) * 2 - 1);
00209     this->data_ = new internal::data< hexa<I> >(ima, b);
00210   }
00211 
00212 
00213   template <typename I>
00214   inline
00215   hexa<I>::hexa()
00216   {
00217   }
00218 
00219 
00220   template <typename I>
00221   inline
00222   hexa<I>::hexa(I& ima)
00223   {
00224     this->init_(ima);
00225   }
00226 
00227   template <typename I>
00228   inline
00229   typename hexa<I>::rvalue
00230   hexa<I>::operator()(const point2d_h& p) const
00231   {
00232     mln_precondition(this->is_valid());
00233     mln_precondition(this->has(p));
00234     return this->data_->ima_(point2d(p[0] / 2, p[1] / 2));
00235   }
00236 
00237   template <typename I>
00238   inline
00239   typename hexa<I>::lvalue
00240   hexa<I>::operator()(const point2d_h& p)
00241   {
00242     mln_precondition(this->is_valid());
00243     mln_precondition(this->has(p));
00244     return this->data_->ima_(point2d(p[0] / 2, p[1] / 2));
00245   }
00246 
00247   template <typename I>
00248   inline
00249   const box2d_h&
00250   hexa<I>::domain() const
00251   {
00252     mln_precondition(this->is_valid());
00253     return this->data_->b_;
00254   }
00255 
00256   template <typename I>
00257   inline
00258   bool
00259   hexa<I>::has(const psite& p) const
00260   {
00261     mln_precondition(this->is_valid());
00262     return this->data_->ima_.has(point2d(p[0] / 2, p[1] / 2));
00263   }
00264 
00265 
00266 # endif // ! MLN_INCLUDE_ONLY
00267 
00268 } // end of namespace mln
00269 
00270 
00271 #endif // ! MLN_CORE_IMAGE_DMORPH_HEXA_HH

Generated on Tue Oct 4 2011 15:23:55 for Milena (Olena) by  doxygen 1.7.1