Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 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_IMORPH_TR_IMAGE_HH 00027 # define MLN_CORE_IMAGE_IMORPH_TR_IMAGE_HH 00028 00033 00034 # include <cmath> 00035 00036 # include <mln/core/internal/image_identity.hh> 00037 # include <mln/algebra/vec.hh> 00038 # include <mln/value/set.hh> 00039 00040 00041 namespace mln 00042 { 00043 00044 // Forward declaration. 00045 template <typename S, typename I, typename T> struct tr_image; 00046 00047 namespace internal 00048 { 00049 00051 template <typename S, typename I, typename T> 00052 struct data< tr_image<S,I,T> > 00053 { 00054 data(const S& s, const I& ima, const T& tr); 00055 00056 I ima_; 00057 T tr_; 00058 S s_; 00059 }; 00060 00061 } // end of namespace mln::internal 00062 00063 namespace trait 00064 { 00065 00066 template <typename S, typename I, typename T> 00067 struct image_< tr_image<S,I,T> > 00068 : public image_<I> // Same as I except... 00069 { 00070 // ...these changes. 00071 typedef trait::image::value_io::read_only value_io; 00072 typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest. 00073 }; 00074 00075 } // end of namespace mln::trait 00076 00077 00081 // 00082 template <typename S, typename I, typename T> 00083 struct tr_image : 00084 public mln::internal::image_identity< I, S, tr_image<S,I,T> > 00085 { 00086 00088 typedef 00089 mln::internal::image_identity< I, S, tr_image<S,I,T> > super_; 00090 00092 typedef mln_psite(I) psite; 00093 00095 typedef mln_site(I) site; 00096 00098 typedef mln_value(I) value; 00099 00101 typedef mln_value(I) lvalue; // FIXME: Depends on lvalue presence in I. 00102 00104 typedef mln_value(I) rvalue; 00105 00107 typedef tr_image< S, tag::image_<I>, T> skeleton; 00108 00109 00111 tr_image(const S& s, const I& ima, const T& tr); 00112 /* FIXME: What's the purpose of this ctor? AFAIK, morphers 00113 objects (and images in general) cannot have their structure / 00114 core data altered after they're built. Here, there's a 00115 (partial) exception: this morpher provides set_tr(), but has no 00116 set_ima(). I (Roland) don't see the point in keeping this ctor 00117 if we do not provide set_ima(). */ 00118 tr_image(); 00119 00121 void init_(const S& s, const I& ima, const T& tr); 00122 00124 bool is_valid() const; 00125 00127 using super_::has; 00128 00129 enum { dim_ = site::dim }; 00130 typedef mln::algebra::vec<dim_, float> vec_t; 00131 00133 bool has(const vec_t& v) const; 00134 00137 //using super_::operator(); 00138 00139 mln_value(I) operator()(const psite& p) const; 00140 mln_value(I) operator()(const psite& p); 00141 00143 void set_tr(T& tr); 00144 00146 const T& tr() const; 00147 00149 const S& domain() const; 00150 }; 00151 00152 00153 00154 # ifndef MLN_INCLUDE_ONLY 00155 00156 namespace internal 00157 { 00158 00159 // internal::data< tr_image<I,S> > 00160 00161 template <typename S, typename I, typename T> 00162 inline 00163 data< tr_image<S,I,T> >::data(const S& s, const I& ima, const T& tr) 00164 : ima_(ima), 00165 tr_(tr), 00166 s_(s) 00167 { 00168 } 00169 00170 } // end of namespace mln::internal 00171 00172 template <typename S, typename I, typename T> 00173 inline 00174 tr_image<S,I,T>::tr_image(const S& s, const I& ima, const T& tr) 00175 { 00176 init_(s, ima, tr); 00177 } 00178 00179 template <typename S, typename I, typename T> 00180 inline 00181 void 00182 tr_image<S,I,T>::init_(const S& s, const I& ima, const T& tr) 00183 { 00184 mln_precondition(ima.is_valid()); 00185 this->data_ = new internal::data< tr_image<S,I,T> >(s, ima, tr); 00186 } 00187 00188 template <typename S, typename I, typename T> 00189 inline 00190 bool 00191 tr_image<S,I,T>::is_valid() const 00192 { 00193 mln_invariant(this->delegatee_()->is_valid()); 00194 return true; 00195 } 00196 00197 template <typename S, typename I, typename T> 00198 inline 00199 bool 00200 tr_image<S,I,T>::has(const vec_t& v) const 00201 { 00202 mln_psite(I) p; 00203 algebra::vec<site::dim, float> v2 = this->data_->tr_.inv()(v); 00204 for (unsigned i = 0; i < site::dim; ++i) 00205 p[i] = static_cast<int>(v2[i]); 00206 return this->delegatee_().has(p); 00207 } 00208 00209 00210 template <typename S, typename I, typename T> 00211 inline 00212 mln_value(I) 00213 tr_image<S,I,T>::operator()(const psite& p) const 00214 { 00215 algebra::vec<site::dim, float> v = p.to_vec(); 00216 return this->data_->ima_(this->data_->tr_.inv()(v)); 00217 } 00218 00219 template <typename S, typename I, typename T> 00220 inline 00221 mln_value(I) 00222 tr_image<S,I,T>::operator()(const psite& p) 00223 { 00224 algebra::vec<site::dim, float> v = p.to_vec(); 00225 return this->data_->ima_(this->data_->tr_.inv()(v)); 00226 } 00227 00228 template <typename S, typename I, typename T> 00229 inline 00230 void 00231 tr_image<S,I,T>::set_tr(T& tr) 00232 { 00233 this->data_->tr_ = tr; 00234 } 00235 00236 template <typename S, typename I, typename T> 00237 inline 00238 const T& 00239 tr_image<S,I,T>::tr() const 00240 { 00241 return this->data_->tr_; 00242 } 00243 00244 template <typename S, typename I, typename T> 00245 inline 00246 const S& 00247 tr_image<S,I,T>::domain() const 00248 { 00249 return this->data_->s_; 00250 } 00251 00252 00253 template <typename S, typename I, typename T> 00254 inline 00255 tr_image<S,I,T> 00256 transposed_image(const Site_Set<S>& s, const Image<I>& ima, 00257 const Function_v2v<T>& t) 00258 { 00259 tr_image<S,I,T> tmp(exact(s), exact(ima), exact(t)); 00260 return tmp; 00261 } 00262 00263 # endif // ! MLN_INCLUDE_ONLY 00264 00265 } // end of namespace mln 00266 00267 00268 #endif // ! MLN_CORE_IMAGE_IMORPH_TR_IMAGE_HH