Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2009, 2010, 2011 EPITA Research and Development 00002 // Laboratory (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project 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 produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 00026 00027 #ifndef MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH 00028 # define MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH 00029 00033 00034 # include <mln/core/internal/labeled_image_base.hh> 00035 00036 # include <mln/core/routine/duplicate.hh> 00037 00038 # include <mln/data/compute.hh> 00039 00040 # include <mln/util/array.hh> 00041 00042 # include <mln/accu/center.hh> 00043 # include <mln/accu/shape/bbox.hh> 00044 # include <mln/accu/stat/max.hh> 00045 00046 # include <mln/data/compute.hh> 00047 00048 # include <mln/labeling/compute.hh> 00049 00050 namespace mln 00051 { 00052 00053 // Forward declarations. 00054 template <typename I> class labeled_image; 00055 namespace accu 00056 { 00057 template <typename T> struct nil; 00058 template <typename T> struct bbox; 00059 } 00060 00061 00062 namespace internal 00063 { 00064 00066 template <typename I> 00067 struct data< labeled_image<I> > 00068 : data< labeled_image_base<I, labeled_image<I> > > 00069 { 00070 typedef data< labeled_image_base<I, labeled_image<I> > > super_; 00071 00072 data(const I& ima, const mln_value(I)& nlabels); 00073 data(const I& ima, const mln_value(I)& nlabels, 00074 const util::array<mln_box(I)>& bboxes); 00075 }; 00076 00077 } // end of namespace mln::internal 00078 00079 00080 namespace trait 00081 { 00082 00083 template <typename I> 00084 struct image_< labeled_image<I> > 00085 : image_< labeled_image_base<I, labeled_image<I> > > 00086 { 00087 }; 00088 00089 } // end of namespace mln::trait 00090 00091 00092 00104 // 00105 template <typename I> 00106 class labeled_image 00107 : public labeled_image_base<I, labeled_image<I> > 00108 { 00109 typedef labeled_image_base<I, labeled_image<I> > super_; 00110 00111 public: 00112 00114 typedef labeled_image< tag::image_<I> > skeleton; 00115 00119 labeled_image(); 00120 00122 labeled_image(const I& ima, const mln_value(I)& nlabels); 00123 00126 labeled_image(const I& ima, const mln_value(I)& nlabels, 00127 const util::array<mln_box(I)>& bboxes); 00129 00132 void init_(const I& ima, const mln_value(I)& nlabels); 00133 00135 void init_from_(const labeled_image<I>& model); 00136 00137 }; 00138 00139 00140 // init_ 00141 00142 //FIXME: not enough generic? We would like 'J' instead of 00143 // 'labeled_image<I>'. 00144 template <typename I, typename J> 00145 void init_(tag::image_t, labeled_image<I>& target, 00146 const labeled_image<J>& model); 00147 00148 00149 00150 namespace make 00151 { 00152 00153 template <typename I> 00154 mln::labeled_image<I> 00155 labeled_image(const Image<I>& ima, const mln_value(I)& nlabels); 00156 00157 } // end of namespace mln::make 00158 00159 00160 00161 00162 # ifndef MLN_INCLUDE_ONLY 00163 00164 00165 // internal::data< labeled_image<I> > 00166 00167 namespace internal 00168 { 00169 00170 00171 // data< labeled_image<I> > 00172 00173 template <typename I> 00174 inline 00175 data< labeled_image<I> >::data(const I& ima, const mln_value(I)& nlabels) 00176 : super_(ima, nlabels) 00177 { 00178 } 00179 00180 template <typename I> 00181 inline 00182 data< labeled_image<I> >::data(const I& ima, const mln_value(I)& nlabels, 00183 const util::array<mln_box(I)>& bboxes) 00184 : super_(ima, nlabels, bboxes) 00185 { 00186 } 00187 00188 00189 } // end of namespace mln::internal 00190 00191 00192 template <typename I> 00193 inline 00194 labeled_image<I>::labeled_image() 00195 { 00196 } 00197 00198 template <typename I> 00199 inline 00200 labeled_image<I>::labeled_image(const I& ima, const mln_value(I)& nlabels) 00201 { 00202 init_(ima, nlabels); 00203 } 00204 00205 template <typename I> 00206 inline 00207 labeled_image<I>::labeled_image(const I& ima, const mln_value(I)& nlabels, 00208 const util::array<mln_box(I)>& bboxes) 00209 { 00210 mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels); 00211 this->data_ = new internal::data< labeled_image<I> >(ima, nlabels, bboxes); 00212 } 00213 00214 00215 template <typename I> 00216 inline 00217 void 00218 labeled_image<I>::init_(const I& ima, const mln_value(I)& nlabels) 00219 { 00220 mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels); 00221 this->data_ = new internal::data< labeled_image<I> >(ima, nlabels); 00222 this->data_->bboxes_ = labeling::compute(accu::meta::shape::bbox(), 00223 this->data_->ima_, 00224 this->data_->nlabels_); 00225 } 00226 00227 template <typename I> 00228 inline 00229 void 00230 labeled_image<I>::init_from_(const labeled_image<I>& model) 00231 { 00232 this->data_ 00233 = new internal::data< labeled_image<I> >(duplicate(model.hook_data_()->ima_), 00234 model.nlabels()); 00235 this->data_->bboxes_ = model.hook_data_()->bboxes_; 00236 } 00237 00238 // init_ 00239 00240 template <typename I, typename J> 00241 void init_(tag::image_t, labeled_image<I>& target, 00242 const labeled_image<J>& model) 00243 { 00244 I ima; 00245 init_(tag::image, ima, model); 00246 target.init_(ima, model.nlabels()); 00247 } 00248 00249 00250 // Make routines. 00251 00252 namespace make 00253 { 00254 00255 template <typename I> 00256 mln::labeled_image<I> 00257 labeled_image(const Image<I>& ima, const mln_value(I)& nlabels) 00258 { 00259 mln_precondition(exact(ima).is_valid()); 00260 mln::labeled_image<I> tmp(exact(ima), nlabels); 00261 return tmp; 00262 } 00263 00264 } // end of namespace mln::make 00265 00266 00267 # endif // ! MLN_INCLUDE_ONLY 00268 00269 } // end of namespace mln 00270 00271 00272 #endif // ! MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH