Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 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_UTIL_PIX_HH 00027 # define MLN_UTIL_PIX_HH 00028 00039 00040 # include <mln/core/concept/image.hh> 00041 00042 00043 namespace mln 00044 { 00045 00047 namespace select 00048 { 00049 00051 template <typename P> 00052 struct p_of : P 00053 { 00054 operator typename P::psite() const 00055 { 00056 return this->p(); 00057 } 00058 }; 00059 00060 } 00061 00062 namespace util 00063 { 00064 00068 template <typename I> 00069 struct pix 00070 { 00071 00073 typedef mln_psite(I) psite; 00074 00076 typedef mln_value(I) value; 00077 00082 pix(const Image<I>& ima, const mln_psite(I)& p); 00083 00087 const I& ima() const; 00088 00092 const mln_psite(I)& p() const; 00093 00097 mln_rvalue(I) v() const; 00098 00099 private: 00100 00102 const I& ima_; 00103 00105 // 00106 // FIXME: Do we want a reference here? 00107 // I (Z) guess we don't since I got invalid values 00108 // when converting a pixter to a util::pix. 00109 // The automatic conversion creates a temporary psite which invalided 00110 // this reference once it was destroyed. see 'operator util::pix()' in 00111 // core/pixter2d.hh. 00112 // 00113 const mln_psite(I) p_; 00114 }; 00115 00116 00117 # ifndef MLN_INCLUDE_ONLY 00118 00119 template <typename I> 00120 inline 00121 pix<I>::pix(const Image<I>& ima, const mln_psite(I)& p) 00122 : ima_(exact(ima)), 00123 p_(p) 00124 { 00125 mln_postcondition(exact(ima).is_valid()); 00126 } 00127 00128 template <typename I> 00129 inline 00130 const I& 00131 pix<I>::ima() const 00132 { 00133 mln_precondition(ima_.is_valid()); 00134 return ima_; 00135 } 00136 00137 template <typename I> 00138 inline 00139 const mln_psite(I)& 00140 pix<I>::p() const 00141 { 00142 mln_precondition(ima_.is_valid()); 00143 mln_precondition(ima_.has(p_)); 00144 return p_; 00145 } 00146 00147 template <typename I> 00148 inline 00149 mln_rvalue(I) 00150 pix<I>::v() const 00151 { 00152 mln_precondition(ima_.is_valid()); 00153 mln_precondition(ima_.has(p_)); 00154 return ima_(p_); 00155 } 00156 00157 # endif // ! MLN_INCLUDE_ONLY 00158 00159 } // end of namespace mln::util 00160 00161 } // end of namespace mln 00162 00163 00164 # include <mln/make/pix.hh> 00165 00166 00167 #endif // ! MLN_UTIL_PIX_HH