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

slice_image.hh

00001 // Copyright (C) 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_SLICE_IMAGE_HH
00027 # define MLN_CORE_IMAGE_DMORPH_SLICE_IMAGE_HH
00028 
00034 
00035 # include <mln/core/internal/image_domain_morpher.hh>
00036 # include <mln/core/alias/box3d.hh>
00037 # include <mln/core/alias/box2d.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043   // Forward declaration.
00044   template <typename I> struct slice_image;
00045 
00046 
00047   namespace internal
00048   {
00049 
00051     template <typename I>
00052     struct data< slice_image<I> >
00053     {
00054       data(I& ima, def::coord sli);
00055 
00056       I ima_;
00057       def::coord sli_;
00058       box2d b_;
00059     };
00060 
00061   } // end of namespace mln::internal
00062 
00063 
00064   namespace trait
00065   {
00066 
00067     template <typename I>
00068     struct image_< slice_image<I> > : default_image_morpher< I,
00069                                                              mln_value(I),
00070                                                              slice_image<I> >
00071     {
00072       typedef trait::image::category::domain_morpher category;
00073 
00074       typedef trait::image::dimension::two_d      dimension;
00075 
00076 //       typedef trait::image::ext_domain::none      ext_domain;  // No extension of domain.
00077 //       typedef trait::image::ext_value::irrelevant ext_value;
00078 //       typedef trait::image::ext_io::irrelevant    ext_io;
00079 
00080       typedef trait::image::vw_io::none                    vw_io;
00081       typedef trait::image::vw_set::none                   vw_set;
00082       typedef trait::image::value_alignment::not_aligned   value_alignment;
00083       typedef trait::image::value_storage::disrupted       value_storage;
00084     };
00085 
00086   } // end of namespace mln::trait
00087 
00088 
00089 
00093   //
00094   template <typename I>
00095   struct slice_image : public internal::image_domain_morpher< I,
00096                                                               box2d,
00097                                                               slice_image<I> >
00098   {
00100     typedef slice_image< tag::image_<I> > skeleton;
00101 
00103     slice_image();
00104 
00106     slice_image(I& ima, def::coord sli);
00107 
00108     void init_(I& ima, def::coord sli);
00109 
00110 
00112     const box2d& domain() const;
00113 
00115     def::coord sli() const;
00116 
00118     mln_rvalue(I) operator()(const point2d& p) const;
00119 
00121     mln_morpher_lvalue(I) operator()(const point2d& p);
00122 
00123 
00125     operator slice_image<const I>() const;
00126   };
00127 
00128 
00129 
00130   template <typename I>
00131   slice_image<I>
00132   slice(Image<I>& ima, def::coord sli);
00133 
00134   template <typename I>
00135   slice_image<const I>
00136   slice(const Image<I>& ima, def::coord sli);
00137 
00138 
00139 
00140 
00141   namespace trait
00142   {
00143 
00144     template <typename I, typename V>
00145     struct ch_value< slice_image<I>, V >
00146     {
00147       typedef image2d<V> ret;
00148     };
00149 
00150   } // end of namespace mln::trait
00151 
00152 
00153 
00154 # ifndef MLN_INCLUDE_ONLY
00155 
00156 
00157 //   // init_.
00158 
00159 //   template <typename I, typename J>
00160 //   void init_(tag::image_t, slice_image<I>& target, const J& model)
00161 //   {
00162 //     I ima;
00163 //     init_(tag::image, ima, exact(model));
00164 //     def::coord sli;
00165 //     // FIXME
00166 //     // init_(tag::???, sli, exact(model));
00167 //     target.init_(ima, sli);
00168 //   }
00169 
00170 
00171   // internal::data< slice_image<I> >
00172 
00173   namespace internal
00174   {
00175 
00176     template <typename I>
00177     inline
00178     data< slice_image<I> >::data(I& ima, def::coord sli)
00179       : ima_(ima),
00180         sli_(sli)
00181     {
00182       b_ = make::box2d(ima.domain().pmin().row(), ima.domain().pmin().col(),
00183                        ima.domain().pmax().row(), ima.domain().pmax().col());
00184     }
00185 
00186   }
00187 
00188 
00189   // slice_image<I>
00190 
00191   template <typename I>
00192   inline
00193   slice_image<I>::slice_image()
00194   {
00195   }
00196 
00197   template <typename I>
00198   inline
00199   slice_image<I>::slice_image(I& ima, def::coord sli)
00200   {
00201     init_(ima, sli);
00202   }
00203 
00204   template <typename I>
00205   inline
00206   void
00207   slice_image<I>::init_(I& ima, def::coord sli)
00208   {
00209     mln_precondition(! this->is_valid());
00210     this->data_ = new internal::data< slice_image<I> >(ima, sli);
00211   }
00212 
00213   template <typename I>
00214   inline
00215   const box2d&
00216   slice_image<I>::domain() const
00217   {
00218     mln_precondition(this->is_valid());
00219     return this->data_->b_;
00220   }
00221 
00222   template <typename I>
00223   inline
00224   def::coord
00225   slice_image<I>::sli() const
00226   {
00227     mln_precondition(this->is_valid());
00228     return this->data_->sli_;
00229   }
00230 
00231   template <typename I>
00232   inline
00233   mln_rvalue(I)
00234   slice_image<I>::operator()(const point2d& p) const
00235   {
00236     mln_precondition(this->has(p));
00237     point3d p_(this->data_->sli_, p.row(), p.col());
00238     mln_precondition(this->data_->ima_.has(p_));
00239     return this->data_->ima_(p_);
00240   }
00241 
00242   template <typename I>
00243   inline
00244   mln_morpher_lvalue(I)
00245   slice_image<I>::operator()(const point2d& p)
00246   {
00247     mln_precondition(this->has(p));
00248     point3d p_(this->data_->sli_, p.row(), p.col());
00249     mln_precondition(this->data_->ima_.has(p_));
00250     return this->data_->ima_(p_);
00251   }
00252 
00253   template <typename I>
00254   inline
00255   slice_image<I>::operator slice_image<const I>() const
00256   {
00257     mln_precondition(this->is_valid());
00258     slice_image<const I> tmp(this->data_->ima_,
00259                              this->data_->sli_);
00260     return tmp;
00261   }
00262 
00263 
00264   // Routines.
00265 
00266   template <typename I>
00267   inline
00268   slice_image<I>
00269   slice(Image<I>& ima_, def::coord sli)
00270   {
00271     mlc_equal(mln_domain(I), box3d)::check();
00272 
00273     I& ima = exact(ima_);
00274     mln_precondition(ima.is_valid());
00275     mln_precondition(sli >= ima.domain().pmin().sli() &&
00276                      sli <= ima.domain().pmax().sli());
00277 
00278     slice_image<I> tmp(ima, sli);
00279     return tmp;
00280   }
00281 
00282   template <typename I>
00283   inline
00284   slice_image<const I>
00285   slice(const Image<I>& ima_, def::coord sli)
00286   {
00287     mlc_equal(mln_domain(I), box3d)::check();
00288 
00289     const I& ima = exact(ima_);
00290     mln_precondition(ima.is_valid());
00291     mln_precondition(sli >= ima.domain().pmin().sli() &&
00292                      sli <= ima.domain().pmax().sli());
00293 
00294     slice_image<const I> tmp(ima, sli);
00295     return tmp;
00296   }
00297 
00298 
00299 # endif // ! MLN_INCLUDE_ONLY
00300 
00301 } // end of namespace mln
00302 
00303 
00304 
00305 #endif // ! MLN_CORE_IMAGE_DMORPH_SLICE_IMAGE_HH

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