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_CORE_PIXEL_HH 00027 # define MLN_CORE_PIXEL_HH 00028 00036 00037 # include <mln/core/concept/generalized_pixel.hh> 00038 # include <mln/core/internal/pixel_impl.hh> 00039 00040 00041 namespace mln 00042 { 00043 00044 00049 template <typename I> 00050 struct pixel : public Object< pixel<I> >, 00051 public Generalized_Pixel< pixel<I> >, 00052 internal::pixel_impl_< I, pixel<I> > 00053 { 00055 pixel(I& image); 00056 00058 pixel(I& image, const mln_psite(I)& p); 00059 00061 void change_to(const mln_psite(I)& p); 00062 00064 bool is_valid() const; 00065 00066 private: 00067 typedef internal::pixel_impl_<I, pixel<I> > super; 00068 }; 00069 00070 00071 # ifndef MLN_INCLUDE_ONLY 00072 00073 template <typename I> 00074 inline 00075 pixel<I>::pixel(I& image) 00076 : super(image) 00077 { 00078 } 00079 00080 template <typename I> 00081 inline 00082 pixel<I>::pixel(I& image, const mln_psite(I)& p) 00083 : super(image) 00084 { 00085 mln_precondition(this->image_.has(p)); 00086 change_to(p); 00087 } 00088 00089 template <typename I> 00090 inline 00091 void 00092 pixel<I>::change_to(const mln_psite(I)& p) 00093 { 00094 mln_precondition(this->image_.has(p)); 00095 this->value_ptr_ = & this->image_(p); 00096 } 00097 00098 template <typename I> 00099 inline 00100 bool 00101 pixel<I>::is_valid() const 00102 { 00103 if (this->value_ptr_ == 0 || ! this->image_.is_valid()) 00104 return false; 00105 int o = this->value_ptr_ - this->image_.buffer(); 00106 mln_psite(I) p = this->image_.point_at_index(o); 00107 return this->image_.has(p); 00108 } 00109 00110 # endif // ! MLN_INCLUDE_ONLY 00111 00112 } // end of namespace mln 00113 00114 00115 # include <mln/make/pixel.hh> 00116 00117 00118 #endif // ! MLN_CORE_PIXEL_HH