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_FUN_X2V_TRILINEAR_HH
00027 # define MLN_FUN_X2V_TRILINEAR_HH
00028
00029 # include <mln/core/image/image2d.hh>
00030 # include <mln/core/concept/function.hh>
00031 # include <mln/fun/internal/selector.hh>
00032 # include <mln/convert/to.hh>
00033 # include <mln/algebra/vec.hh>
00034
00040
00041 namespace mln
00042 {
00043
00044 namespace fun
00045 {
00046
00047 namespace x2v
00048 {
00049
00052 template < typename I >
00053 struct trilinear
00054 : public fun::internal::selector_<const algebra::vec<3,float>,
00055
00056 mln_value(I), trilinear<I> >::ret
00057 {
00058 typedef mln_value(I) result;
00059
00060 trilinear(const I& ima);
00061
00062 template <typename T>
00063 mln_value(I)
00064 operator()(const algebra::vec<3,T>& v) const;
00065
00066 const I& ima;
00067 };
00068
00069
00070 # ifndef MLN_INCLUDE_ONLY
00071
00072 template <typename I>
00073 trilinear<I>::trilinear(const I& ima) : ima(ima)
00074 {
00075 mlc_bool(I::psite::dim == 3)::check();
00076 }
00077
00078
00079 template <typename I>
00080 template <typename T>
00081 mln_value(I)
00082 trilinear<I>::operator()(const algebra::vec<3,T>& v) const
00083 {
00084 typedef mln_sum(mln_value(I)) vsum;
00085
00086 double x = v[0];
00087 double y = v[1];
00088 double z = v[2];
00089
00090 math::round<double> f;
00091 unsigned x1 = f(std::floor(x));
00092 unsigned x2 = f(std::floor(x) + 1);
00093 unsigned y1 = f(std::floor(y));
00094 unsigned y2 = f(std::floor(y) + 1);
00095 unsigned z1 = f(std::floor(z));
00096 unsigned z2 = f(std::floor(z) + 1);
00097
00098 double xd = x - x1;
00099 double yd = y - y1;
00100 double zd = z - z1;
00101
00102
00103
00104 vsum i1 = ima(point3d(z1,x1,y1)) * (1 - zd)
00105 + ima(point3d(z2,x1,y1)) * zd;
00106
00107 vsum i2 = ima(point3d(z1,x1,y2)) * (1 - zd)
00108 + ima(point3d(z2,x1,y2)) * zd;
00109
00110 vsum j1 = ima(point3d(z1,x2,y1)) * (1 - zd)
00111 + ima(point3d(z2,x2,y1)) * zd;
00112
00113 vsum j2 = ima(point3d(z1,x2,y2)) * (1 - zd)
00114 + ima(point3d(z2,x2,y2)) * zd;
00115
00116
00117 vsum w1 = i1 * (1 - yd) + i2 * yd;
00118 vsum w2 = j1 * (1 - yd) + j2 * yd;
00119
00120
00121 vsum res = w1 * (1 - xd) + w2 * xd;
00122
00123 return convert::to<mln_value(I)>(res);
00124 }
00125
00126
00127 # endif // ! MLN_INCLUDE_ONLY
00128
00129 }
00130
00131 }
00132
00133 }
00134
00135
00136 #endif // ! MLN_FUN_X2V_TRILINEAR_HH