00001 #ifndef IMAGE_CASTACCESSOR_H 00002 #define IMAGE_CASTACCESSOR_H 00003 00004 00005 #include <image/ImageAccessorInterface.hpp> 00006 00007 namespace imaging 00008 { 00009 00016 template <class image_t, class DATA_t = float_t> 00017 class CastAccessor : public ImageAccessorInterface<image_t, DATA_t> 00018 { 00019 public: 00020 static const size_t dimension = ImageAccessorInterface<image_t, DATA_t>::dimension; 00021 typedef DATA_t data_t; 00022 00023 private: 00025 class data_reference 00026 { 00027 CastAccessor<image_t, DATA_t> & _accessor_reference; 00028 const ublas::fixed_vector<size_t, dimension> & _index_reference; 00029 00030 public: 00031 data_reference(CastAccessor<image_t, DATA_t> & accessor, const ublas::fixed_vector<size_t, dimension> & index) : _accessor_reference(accessor), _index_reference(index) {} 00032 00033 DATA_t operator=(const DATA_t & input) 00034 { _accessor_reference._image_reference[_index_reference] = (typename image_t::data_t)(input); return input; } 00035 00036 operator DATA_t() const { return DATA_t(_accessor_reference._image_reference[_index_reference]); } 00037 }; 00040 public: 00044 CastAccessor(image_t & image) : ImageAccessorInterface<image_t, DATA_t>(image) {} 00045 00046 DATA_t operator[](const ublas::fixed_vector<size_t, dimension> & index) const { return DATA_t(ImageAccessorInterface<image_t, DATA_t>::_image_reference[index]); } 00047 data_reference operator[](const ublas::fixed_vector<size_t, dimension> & index) { return data_reference(*this, index); } 00048 }; 00049 00050 } 00051 00052 #endif