Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009, 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_DMORPH_HEXA_HH 00028 # define MLN_CORE_IMAGE_DMORPH_HEXA_HH 00029 00030 00035 00036 # include <mln/core/internal/image_domain_morpher.hh> 00037 # include <mln/core/alias/point2d_h.hh> 00038 # include <mln/core/alias/box2d_h.hh> 00039 # include <mln/core/image/dmorph/hexa_piter.hh> 00040 00041 00042 namespace mln 00043 { 00044 00045 // Forward declaration. 00046 template <typename I> struct hexa; 00047 00048 00049 namespace internal 00050 { 00052 template <typename I> 00053 struct data< hexa<I> > 00054 { 00055 data(I& ima, box2d_h b); 00056 00057 I ima_; 00058 mln::box2d_h b_; 00059 }; 00060 00061 } // end of namespace mln::internal 00062 00063 00064 namespace trait 00065 { 00067 template <typename I> 00068 struct image_< hexa<I> > : default_image_morpher< I, mln_value(I), 00069 hexa<I> > 00070 { 00071 // private: 00072 // typedef mln_trait_image_data(I) I_data_; 00073 // typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_; 00074 // public: 00075 00076 typedef trait::image::category::domain_morpher category; 00077 00078 typedef mln_trait_image_pw_io(I) pw_io; // un-write when I const 00079 typedef mln_trait_image_dimension(I) dimension; 00080 00081 // Extended domain 00082 typedef mln_trait_image_ext_domain(I) ext_domain; // have a border only if I does. 00083 typedef mln_trait_image_ext_value(I) ext_value; 00084 typedef mln_trait_image_ext_io(I) ext_io; // un-write when I const 00085 00086 // typedef mlc_if( I_data_are_linear_, 00087 // trait::data::stored, // if linear then just stored 00088 // I_data_ ) data; // otherwise like I 00089 }; 00090 00091 } // end of namespace mln::trait 00092 00093 00116 template <typename I> 00117 struct hexa : 00118 public internal::image_domain_morpher< I, box2d_h, hexa<I> > 00119 { 00121 typedef hexa< tag::image_<I> > skeleton; 00122 00124 typedef mln_value(I) value; 00125 00127 typedef mln_lvalue(I) lvalue; 00128 00130 typedef mln_rvalue(I) rvalue; 00131 00133 typedef point2d_h psite; 00134 00137 typedef hexa_fwd_piter_<box2d> fwd_piter; 00138 00141 typedef hexa_bkd_piter_<box2d> bkd_piter; 00142 00143 00145 hexa(); 00146 00148 hexa(I& ima); 00149 00151 void init_(I& ima); 00152 00154 const box2d_h& domain() const; 00155 00157 bool has(const psite& p) const; 00158 00160 rvalue operator()(const point2d_h& p) const; 00161 00163 lvalue operator()(const point2d_h& p); 00164 }; 00165 00166 template <typename I, typename J> 00167 void init_(tag::image_t, hexa<I>& target, const J& model); 00168 00169 # ifndef MLN_INCLUDE_ONLY 00170 00171 00172 // init_ 00173 00174 template <typename I, typename J> 00175 inline 00176 void init_(tag::image_t, hexa<I>& target, const J& model) 00177 { 00178 I ima; 00179 init_(tag::image, ima, model); 00180 target.init_(ima); 00181 } 00182 00183 00184 00185 // internal::data< hexa<I> > 00186 00187 namespace internal 00188 { 00189 00190 template <typename I> 00191 inline 00192 data< hexa<I> >::data(I& ima, box2d_h b) 00193 : ima_(ima), 00194 b_(b) 00195 { 00196 } 00197 00198 } // end of namespace mln::internal 00199 00200 00201 template <typename I> 00202 inline 00203 void 00204 hexa<I>::init_(I& ima) 00205 { 00206 mln_precondition(! this->is_valid()); 00207 box2d b_in = ima.bbox(); 00208 box2d_h b = make::box2d_h(b_in.pmin()[0] * 2, b_in.pmin()[1], 00209 b_in.pmax()[0] * 2, (b_in.pmax()[1] + 1) * 2 - 1); 00210 this->data_ = new internal::data< hexa<I> >(ima, b); 00211 } 00212 00213 00214 template <typename I> 00215 inline 00216 hexa<I>::hexa() 00217 { 00218 } 00219 00220 00221 template <typename I> 00222 inline 00223 hexa<I>::hexa(I& ima) 00224 { 00225 this->init_(ima); 00226 } 00227 00228 template <typename I> 00229 inline 00230 typename hexa<I>::rvalue 00231 hexa<I>::operator()(const point2d_h& p) const 00232 { 00233 mln_precondition(this->is_valid()); 00234 mln_precondition(this->has(p)); 00235 return this->data_->ima_(point2d(p[0] / 2, p[1] / 2)); 00236 } 00237 00238 template <typename I> 00239 inline 00240 typename hexa<I>::lvalue 00241 hexa<I>::operator()(const point2d_h& p) 00242 { 00243 mln_precondition(this->is_valid()); 00244 mln_precondition(this->has(p)); 00245 return this->data_->ima_(point2d(p[0] / 2, p[1] / 2)); 00246 } 00247 00248 template <typename I> 00249 inline 00250 const box2d_h& 00251 hexa<I>::domain() const 00252 { 00253 mln_precondition(this->is_valid()); 00254 return this->data_->b_; 00255 } 00256 00257 template <typename I> 00258 inline 00259 bool 00260 hexa<I>::has(const psite& p) const 00261 { 00262 mln_precondition(this->is_valid()); 00263 return this->data_->ima_.has(point2d(p[0] / 2, p[1] / 2)); 00264 } 00265 00266 00267 # endif // ! MLN_INCLUDE_ONLY 00268 00269 } // end of namespace mln 00270 00271 00272 #endif // ! MLN_CORE_IMAGE_DMORPH_HEXA_HH