00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef IMAGE_INTERPOLATIONADAPTORINTERFACE_H
00010 #define IMAGE_INTERPOLATIONADAPTORINTERFACE_H
00011
00012
00013 namespace imaging
00014 {
00015 namespace interpolation_adaptor_impl
00016 {
00017 template <size_t N>
00018 bool offset_position(const ublas::fixed_vector<size_t, N> & size, const ublas::fixed_vector<float_t, N> & position, ublas::fixed_vector<float_t, N> & out)
00019 {
00020 for(size_t i = 0; i < N; ++i)
00021 {
00022 if(position(i) < 0.0 || position(i) >= float_t(size(i)) || size(i) < 2)
00023 {
00024 return false;
00025 }
00026
00027 if(position(i) <= 0.5)
00028 out(i) = 0.0;
00029 else if(position(i) >= float_t(size(i)) - 0.5)
00030 out(i) = float_t(size(i) - 1);
00031 else
00032 out(i) = position(i) - 0.5;
00033 }
00034
00035 return true;
00036 }
00037
00038 template <size_t N>
00039 void compute_local_coordinates(const ublas::fixed_vector<float_t, N> & index, const ublas::fixed_vector<size_t, N> & size, ublas::fixed_vector<size_t, N> & base_coordinates, ublas::fixed_vector<float_t, N> & truncated_coordinates)
00040 {
00041 for(size_t i = 0; i < N; ++i)
00042 {
00043 base_coordinates(i) = size_t(floor(index(i)));
00044 truncated_coordinates(i) = index(i) - float_t(base_coordinates(i));
00045
00046 if(base_coordinates(i) == size(i) - 1)
00047 {
00048 base_coordinates(i)--;
00049 truncated_coordinates(i) = 1.0;
00050 }
00051 }
00052 }
00053 }
00054
00055 template <class image_t>
00056 class PolynomialInterpolationAdaptor;
00057
00058 template <class image_t>
00059 class LinearInterpolationAdaptor;
00060
00061 template <class image_t>
00062 class MeanInterpolationAdaptor;
00063
00071 template <class image_t>
00072 class InterpolationAdaptorInterface
00073 {
00074 friend class PolynomialInterpolationAdaptor<image_t>;
00075 friend class LinearInterpolationAdaptor<image_t>;
00076 friend class MeanInterpolationAdaptor<image_t>;
00077
00078 const image_t & _image_reference;
00079
00080 InterpolationAdaptorInterface(const image_t & image_reference) : _image_reference(image_reference)
00081 {}
00082
00083 public:
00085 typedef typename image_t::data_t data_t;
00086
00088 static const std::size_t dimension;
00089
00091 const ublas::fixed_vector<size_t, image_t::dimension> & size() const
00092 {
00093 return _image_reference.size();
00094 }
00095
00097 data_t operator[](const ublas::fixed_vector<float_t, image_t::dimension> & index);
00098 };
00099
00100 template <class image_t>
00101 const std::size_t InterpolationAdaptorInterface<image_t>::dimension = image_t::dimension;
00102 }
00103
00104 #endif