ScalingAccessor.hpp

00001 #ifndef IMAGE_SCALINGACCESSOR_H
00002 #define IMAGE_SCALINGACCESSOR_H
00003 
00004 #include <image/ImageAccessorInterface.hpp>
00005 
00006 namespace imaging
00007 {
00025   template <class float_accessor_t>
00026   class ScalingAccessor : public ImageAccessorInterface<float_accessor_t, float_t>
00027   {
00028   public:
00029     static const size_t dimension = ImageAccessorInterface<float_accessor_t, float_t>::dimension;
00030     typedef float_t data_t;
00031 
00032   private:
00034     class data_reference
00035     {
00036       ScalingAccessor<float_accessor_t> & _accessor_reference;
00037       const ublas::fixed_vector<size_t, dimension> & _index_reference;
00038 
00039     public:
00040       data_reference(ScalingAccessor<float_accessor_t> & accessor, const ublas::fixed_vector<size_t, dimension> & index) : _accessor_reference(accessor), _index_reference(index) {}
00041 
00042       float_t operator=(const float_t & input)
00043       { _accessor_reference._image_reference[_index_reference] = input / _accessor_reference._factor - _accessor_reference._level; return input; }
00044 
00045       operator float_t() const { return  _accessor_reference._factor * (_accessor_reference._image_reference[_index_reference] + _accessor_reference._level); }
00046     };
00049     float_t _factor;
00050     float_t _level;
00051 
00052   public:
00055     ScalingAccessor(float_accessor_t & image, float_t factor = 1.0, float_t level = 0.0) :
00056     ImageAccessorInterface<float_accessor_t, float_t>(image), _factor(factor), _level(level) {}
00057 
00058     float_t operator[](const ublas::fixed_vector<size_t, dimension> & index) const { return _factor * (ImageAccessorInterface<float_accessor_t, float_t>::_image_reference[index] + _level); }
00059     data_reference operator[](const ublas::fixed_vector<size_t, dimension> & index) { return data_reference(*this, index); }
00060   };
00061 
00062 }
00063 
00064 #endif

Generated on Tue Feb 10 10:01:30 2009 for imaging2 by  doxygen 1.5.5