Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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_UNPROJECT_IMAGE_HH 00027 # define MLN_CORE_IMAGE_DMORPH_UNPROJECT_IMAGE_HH 00028 00033 00034 # include <mln/core/internal/image_domain_morpher.hh> 00035 # include <mln/core/grids.hh> 00036 # include <mln/core/site_set/box.hh> 00037 00038 00039 namespace mln 00040 { 00041 00042 00043 // Forward declaration. 00044 template <typename I, typename D, typename F> struct unproject_image; 00045 00046 00047 namespace internal 00048 { 00049 00051 template <typename I, typename D, typename F> 00052 struct data< unproject_image<I,D,F> > 00053 { 00054 data(I& ima, const D& dom, const F& f); 00055 00056 I ima_; 00057 D dom_; 00058 F f_; 00059 }; 00060 00061 } // end of namespace mln::internal 00062 00063 00064 namespace trait 00065 { 00066 00067 template <typename I, typename D, typename F> 00068 struct image_< unproject_image<I,D,F> > : default_image_morpher< I, 00069 mln_value(I), 00070 unproject_image<I,D,F> > 00071 { 00072 typedef trait::image::category::domain_morpher category; 00073 00074 // FIXME: 00075 // typedef trait::image::dimension::two_d dimension; 00076 00077 typedef trait::image::ext_domain::none ext_domain; // No extension of domain. 00078 typedef trait::image::ext_value::irrelevant ext_value; 00079 typedef trait::image::ext_io::irrelevant ext_io; 00080 00081 typedef trait::image::vw_io::none vw_io; 00082 typedef trait::image::vw_set::none vw_set; 00083 typedef trait::image::value_alignment::not_aligned value_alignment; 00084 typedef trait::image::value_storage::disrupted value_storage; 00085 }; 00086 00087 } // end of namespace mln::trait 00088 00089 00090 00094 // 00095 template <typename I, typename D, typename F> 00096 struct unproject_image : public internal::image_domain_morpher< I, 00097 D, 00098 unproject_image<I,D,F> > 00099 { 00100 // FIXME: 00101 typedef void skeleton; 00102 // /// Skeleton. 00103 // typedef unproject_image< tag::image_<I> > skeleton; 00104 00105 00107 unproject_image(); 00108 00110 unproject_image(I& ima, const D& dom, const F& f); 00111 00112 void init_(I& ima, const D& dom, const F& f); 00113 00114 00116 const D& domain() const; 00117 00119 mln_rvalue(I) operator()(const mln_psite(D)& p) const; 00120 00122 mln_morpher_lvalue(I) operator()(const mln_psite(D)& p); 00123 00124 00125 // /// Const promotion via conversion. 00126 // operator unproject_image<const I, D, F>() const; 00127 }; 00128 00129 00130 00131 template <typename I, typename D, typename F> 00132 unproject_image<I, D, F> 00133 unproject(Image<I>& ima, const Site_Set<D>& dom, const Function_v2v<F>& f); 00134 00135 template <typename I, typename D, typename F> 00136 unproject_image<const I, D, F> 00137 unproject(const Image<I>& ima, const Site_Set<D>& dom, const Function_v2v<F>& f); 00138 00139 00140 00141 00142 // namespace trait 00143 // { 00144 00145 // template <typename I, typename D, typename F, 00146 // typename V> 00147 // struct ch_value< unproject_image<I,D,F>, V > 00148 // { 00149 // // FIXME: Somthing like: 00150 // typedef pw::image< pw::cst_<mln_value(I)>, D> I_; 00151 // typedef mln_ch_value(I_,V) ret; 00152 // }; 00153 00154 // } // end of namespace mln::trait 00155 00156 00157 00158 # ifndef MLN_INCLUDE_ONLY 00159 00160 00161 // internal::data< unproject_image<I,D,F> > 00162 00163 namespace internal 00164 { 00165 00166 template <typename I, typename D, typename F> 00167 inline 00168 data< unproject_image<I,D,F> >::data(I& ima, const D& dom, const F& f) 00169 : ima_(ima), 00170 dom_(dom), 00171 f_(f) 00172 { 00173 } 00174 00175 } 00176 00177 00178 // unproject_image<I,D,F> 00179 00180 template <typename I, typename D, typename F> 00181 inline 00182 unproject_image<I,D,F>::unproject_image() 00183 { 00184 } 00185 00186 template <typename I, typename D, typename F> 00187 inline 00188 unproject_image<I,D,F>::unproject_image(I& ima, const D& dom, const F& f) 00189 { 00190 init_(ima, dom, f); 00191 } 00192 00193 template <typename I, typename D, typename F> 00194 inline 00195 void 00196 unproject_image<I,D,F>::init_(I& ima, const D& dom, const F& f) 00197 { 00198 mln_precondition(! this->is_valid()); 00199 this->data_ = new internal::data< unproject_image<I,D,F> >(ima, dom, f); 00200 } 00201 00202 template <typename I, typename D, typename F> 00203 inline 00204 const D& 00205 unproject_image<I,D,F>::domain() const 00206 { 00207 mln_precondition(this->is_valid()); 00208 return this->data_->dom_; 00209 } 00210 00211 template <typename I, typename D, typename F> 00212 inline 00213 mln_rvalue(I) 00214 unproject_image<I,D,F>::operator()(const mln_psite(D)& p) const 00215 { 00216 mln_precondition(this->has(p)); 00217 mln_result(F) p_ = this->data_->f_(p); 00218 mln_precondition(this->data_->ima_.has(p_)); 00219 return this->data_->ima_(p_); 00220 } 00221 00222 template <typename I, typename D, typename F> 00223 inline 00224 mln_morpher_lvalue(I) 00225 unproject_image<I,D,F>::operator()(const mln_psite(D)& p) 00226 { 00227 mln_precondition(this->has(p)); 00228 mln_result(F) p_ = this->data_->f_(p); 00229 mln_precondition(this->data_->ima_.has(p_)); 00230 return this->data_->ima_(p_); 00231 } 00232 00233 00234 // Routines. 00235 00236 template <typename I, typename D, typename F> 00237 inline 00238 unproject_image<I, D, F> 00239 unproject(Image<I>& ima_, const Site_Set<D>& dom, const Function_v2v<F>& f) 00240 { 00241 mlc_converts_to(mln_psite(D), mln_argument(F))::check(); 00242 mlc_converts_to(mln_result(F), mln_psite(I))::check(); 00243 00244 I& ima = exact(ima_); 00245 mln_precondition(ima.is_valid()); 00246 00247 unproject_image<I,D,F> tmp(ima, exact(dom), exact(f)); 00248 return tmp; 00249 } 00250 00251 template <typename I, typename D, typename F> 00252 inline 00253 unproject_image<const I, D, F> 00254 unproject(const Image<I>& ima_, const Site_Set<D>& dom, const Function_v2v<F>& f) 00255 { 00256 mlc_converts_to(mln_psite(D), mln_argument(F))::check(); 00257 mlc_converts_to(mln_result(F), mln_psite(I))::check(); 00258 00259 const I& ima = exact(ima_); 00260 mln_precondition(ima.is_valid()); 00261 00262 unproject_image<const I,D,F> tmp(ima, exact(dom), exact(f)); 00263 return tmp; 00264 } 00265 00266 00267 # endif // ! MLN_INCLUDE_ONLY 00268 00269 } // end of namespace mln 00270 00271 00272 00273 #endif // ! MLN_CORE_IMAGE_DMORPH_UNPROJECT_IMAGE_HH