Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 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_INTERPOLATED_HH 00028 # define MLN_CORE_IMAGE_IMORPH_INTERPOLATED_HH 00029 00036 00037 00038 # include <cmath> 00039 00040 # include <mln/core/internal/image_identity.hh> 00041 # include <mln/algebra/vec.hh> 00042 # include <mln/value/set.hh> 00043 00044 namespace mln 00045 { 00046 00047 // Forward declaration. 00048 template <typename I, template <class> class F> struct interpolated; 00049 00050 namespace internal 00051 { 00052 00054 template <typename I, template <class> class F> 00055 struct data< interpolated<I,F> > 00056 { 00057 data(I& ima); 00058 00059 I& ima_; 00060 }; 00061 00062 } // end of namespace mln::internal 00063 00064 00065 namespace trait 00066 { 00067 00068 template <typename I, template <class> class F> 00069 struct image_< interpolated<I,F> > 00070 : public image_<I> // Same as I except... 00071 { 00072 // ...these changes. 00073 typedef trait::image::value_io::read_only value_io; 00074 }; 00075 00076 } // end of namespace mln::trait 00077 00078 00082 // 00083 template <typename I, template <class> class F> 00084 struct interpolated : 00085 public mln::internal::image_identity< I, mln_domain(I), interpolated<I,F> > 00086 { 00087 00088 typedef mln::internal::image_identity< I, mln_domain(I), 00089 interpolated<I,F> > super_; 00090 00092 typedef mln_psite(I) psite; 00093 00095 typedef mln_value(I) value; 00096 00098 typedef mln_lvalue(I) lvalue; // FIXME: Depends on lvalue presence in I. 00099 00101 typedef mln_rvalue(I) rvalue; 00102 00104 typedef interpolated< tag::image_<I>, F > skeleton; 00105 00106 00109 interpolated(I& ima); 00110 interpolated(); 00111 00113 void init_(I& ima); 00114 00115 00117 bool is_valid() const; 00118 00120 using super_::has; 00121 00123 template <typename C> 00124 bool has(const mln::algebra::vec<I::psite::dim, C>& v) const; 00125 00128 using super_::operator(); 00129 00130 mln_value(I) operator()(const mln::algebra::vec<psite::dim, float>& v) const; 00131 mln_value(I) operator()(const mln::algebra::vec<psite::dim, float>& v); 00132 00133 const F<I> fun_; 00134 }; 00135 00136 00137 00138 # ifndef MLN_INCLUDE_ONLY 00139 00140 namespace internal 00141 { 00142 00143 // internal::data< interpolated<I,S> > 00144 00145 template <typename I, template <class> class F> 00146 inline 00147 data< interpolated<I,F> >::data(I& ima) 00148 : ima_(ima) 00149 { 00150 } 00151 00152 } // end of namespace mln::internal 00153 00154 template <typename I, template <class> class F> 00155 inline 00156 interpolated<I,F>::interpolated(I& ima) 00157 : fun_(ima) 00158 { 00159 mln_precondition(ima.is_valid()); 00160 init_(ima); 00161 } 00162 00163 template <typename I, template <class> class F> 00164 inline 00165 interpolated<I,F>::interpolated() 00166 { 00167 } 00168 00169 template <typename I, template <class> class F> 00170 inline 00171 void 00172 interpolated<I, F >::init_(I& ima) 00173 { 00174 mln_precondition(ima.is_valid()); 00175 this->data_ = new internal::data< interpolated<I,F> >(ima); 00176 } 00177 00178 template <typename I, template <class> class F> 00179 inline 00180 bool interpolated<I,F>::is_valid() const 00181 { 00182 mln_invariant(this->data_->ima_.is_valid()); 00183 return true; 00184 } 00185 00186 template <typename I, template <class> class F> 00187 template <typename C> 00188 inline 00189 bool interpolated<I,F>::has(const mln::algebra::vec<I::psite::dim, C>& v) const 00190 { 00191 mln_psite(I) p; 00192 for (unsigned i = 0; i < I::psite::dim; ++i) 00193 p[i] = static_cast<int>(round(v[i])); 00194 return this->data_->ima_.has(p); 00195 } 00196 00197 00198 template <typename I, template <class> class F> 00199 inline 00200 mln_value(I) 00201 interpolated<I,F>::operator()(const mln::algebra::vec<psite::dim, float>& v) const 00202 { 00203 return fun_(v); 00204 } 00205 00206 template <typename I, template <class> class F> 00207 inline 00208 mln_value(I) 00209 interpolated<I,F>::operator()(const mln::algebra::vec<psite::dim, float>& v) 00210 { 00211 return fun_(v); 00212 } 00213 00214 00215 # endif // ! MLN_INCLUDE_ONLY 00216 00217 } // end of namespace mln 00218 00219 00220 #endif // ! MLN_CORE_IMAGE_IMORPH_INTERPOLATED_HH