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

labeled_image.hh

00001 // Copyright (C) 2009, 2010 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_IMORPH_LABELED_IMAGE_HH
00027 # define MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH
00028 
00032 
00033 # include <mln/core/internal/labeled_image_base.hh>
00034 
00035 # include <mln/core/routine/duplicate.hh>
00036 
00037 # include <mln/data/compute.hh>
00038 
00039 # include <mln/util/array.hh>
00040 
00041 # include <mln/accu/center.hh>
00042 # include <mln/accu/shape/bbox.hh>
00043 # include <mln/accu/stat/max.hh>
00044 
00045 # include <mln/data/compute.hh>
00046 
00047 # include <mln/labeling/compute.hh>
00048 
00049 namespace mln
00050 {
00051 
00052   // Forward declarations.
00053   template <typename I> struct labeled_image;
00054   namespace accu
00055   {
00056     template <typename T> struct nil;
00057     template <typename T> struct bbox;
00058   }
00059 
00060 
00061   namespace internal
00062   {
00063 
00065     template <typename I>
00066     struct data< labeled_image<I> >
00067       : data< labeled_image_base<I, labeled_image<I> > >
00068     {
00069       typedef data< labeled_image_base<I, labeled_image<I> > > super_;
00070 
00071       data(const I& ima, const mln_value(I)& nlabels);
00072       data(const I& ima, const mln_value(I)& nlabels,
00073            const util::array<mln_box(I)>& bboxes);
00074     };
00075 
00076   } // end of namespace mln::internal
00077 
00078 
00079   namespace trait
00080   {
00081 
00082     template <typename I>
00083     struct image_< labeled_image<I> >
00084       : image_< labeled_image_base<I, labeled_image<I> > >
00085     {
00086     };
00087 
00088   } // end of namespace mln::trait
00089 
00090 
00091 
00103   //
00104   template <typename I>
00105   class labeled_image
00106     : public labeled_image_base<I, labeled_image<I> >
00107   {
00108     typedef labeled_image_base<I, labeled_image<I> > super_;
00109 
00110   public:
00111 
00113     typedef labeled_image< tag::image_<I> > skeleton;
00114 
00118     labeled_image();
00119 
00121     labeled_image(const I& ima, const mln_value(I)& nlabels);
00122 
00125     labeled_image(const I& ima, const mln_value(I)& nlabels,
00126                   const util::array<mln_box(I)>& bboxes);
00128 
00131     void init_(const I& ima, const mln_value(I)& nlabels);
00132 
00134     void init_from_(const labeled_image<I>& model);
00135 
00136   };
00137 
00138 
00139   // init_
00140 
00141   //FIXME: not enough generic? We would like 'J' instead of
00142   // 'labeled_image<I>'.
00143   template <typename I, typename J>
00144   void init_(tag::image_t, labeled_image<I>& target,
00145              const labeled_image<J>& model);
00146 
00147 
00148 
00149   namespace make
00150   {
00151 
00152     template <typename I>
00153     mln::labeled_image<I>
00154     labeled_image(const Image<I>& ima, const mln_value(I)& nlabels);
00155 
00156   } // end of namespace mln::make
00157 
00158 
00159 
00160 
00161 # ifndef MLN_INCLUDE_ONLY
00162 
00163 
00164   // internal::data< labeled_image<I> >
00165 
00166   namespace internal
00167   {
00168 
00169 
00170     // data< labeled_image<I> >
00171 
00172     template <typename I>
00173     inline
00174     data< labeled_image<I> >::data(const I& ima, const mln_value(I)& nlabels)
00175       : super_(ima, nlabels)
00176     {
00177     }
00178 
00179     template <typename I>
00180     inline
00181     data< labeled_image<I> >::data(const I& ima, const mln_value(I)& nlabels,
00182                                    const util::array<mln_box(I)>& bboxes)
00183       : super_(ima, nlabels, bboxes)
00184     {
00185     }
00186 
00187 
00188   } // end of namespace mln::internal
00189 
00190 
00191   template <typename I>
00192   inline
00193   labeled_image<I>::labeled_image()
00194   {
00195   }
00196 
00197   template <typename I>
00198   inline
00199   labeled_image<I>::labeled_image(const I& ima, const mln_value(I)& nlabels)
00200   {
00201     init_(ima, nlabels);
00202   }
00203 
00204   template <typename I>
00205   inline
00206   labeled_image<I>::labeled_image(const I& ima, const mln_value(I)& nlabels,
00207                                   const util::array<mln_box(I)>& bboxes)
00208   {
00209     mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels);
00210     this->data_ = new internal::data< labeled_image<I> >(ima, nlabels, bboxes);
00211   }
00212 
00213 
00214   template <typename I>
00215   inline
00216   void
00217   labeled_image<I>::init_(const I& ima, const mln_value(I)& nlabels)
00218   {
00219     mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels);
00220     this->data_ = new internal::data< labeled_image<I> >(ima, nlabels);
00221     this->data_->bboxes_ = labeling::compute(accu::meta::shape::bbox(),
00222                                              this->data_->ima_,
00223                                              this->data_->nlabels_);
00224  }
00225 
00226   template <typename I>
00227   inline
00228   void
00229   labeled_image<I>::init_from_(const labeled_image<I>& model)
00230   {
00231     this->data_
00232       = new internal::data< labeled_image<I> >(duplicate(model.hook_data_()->ima_),
00233                                                  model.nlabels());
00234     this->data_->bboxes_ = model.hook_data_()->bboxes_;
00235   }
00236 
00237   // init_
00238 
00239   template <typename I, typename J>
00240   void init_(tag::image_t, labeled_image<I>& target,
00241              const labeled_image<J>& model)
00242   {
00243     I ima;
00244     init_(tag::image, ima, model);
00245     target.init_(ima, model.nlabels());
00246   }
00247 
00248 
00249   // Make routines.
00250 
00251   namespace make
00252   {
00253 
00254     template <typename I>
00255     mln::labeled_image<I>
00256     labeled_image(const Image<I>& ima, const mln_value(I)& nlabels)
00257     {
00258       mln_precondition(exact(ima).is_valid());
00259       mln::labeled_image<I> tmp(exact(ima), nlabels);
00260       return tmp;
00261     }
00262 
00263   } // end of namespace mln::make
00264 
00265 
00266 # endif // ! MLN_INCLUDE_ONLY
00267 
00268 } // end of namespace mln
00269 
00270 
00271 #endif // ! MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH

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