00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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 } 
00113 
00114 
00115 # include <mln/make/pixel.hh>
00116 
00117 
00118 #endif // ! MLN_CORE_PIXEL_HH