00001
00002 #ifndef vil_bicub_interp_txx_
00003 #define vil_bicub_interp_txx_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "vil_bicub_interp.h"
00018 #include <vcl_compiler.h>
00019
00020
00021
00022
00023
00024
00025
00026
00027 template<class T>
00028 double vil_bicub_interp_unsafe(double x, double y, const T* data,
00029 vcl_ptrdiff_t xstep, vcl_ptrdiff_t ystep)
00030 {
00031 int p1x=int(x);
00032 double normx = x-p1x;
00033 int p1y=int(y);
00034 double normy = y-p1y;
00035
00036 const T* pix1 = data + p1y*ystep + p1x*xstep;
00037
00038
00039
00040 double s0 = ((2-normx)*normx-1)*normx;
00041 double s1 = (3*normx-5)*normx*normx+2;
00042 double s2 = ((4-3*normx)*normx+1)*normx;
00043 double s3 = (normx-1)*normx*normx;
00044
00045 double t0 = ((2-normy)*normy-1)*normy;
00046 double t1 = (3*normy-5)*normy*normy+2;
00047 double t2 = ((4-3*normy)*normy+1)*normy;
00048 double t3 = (normy-1)*normy*normy;
00049
00050 #define vil_I(dx,dy) (pix1[(dx)*xstep+(dy)*ystep])
00051
00052 double xi0 = s0*vil_I(-1,-1) + s1*vil_I(+0,-1) + s2*vil_I(+1,-1) + s3*vil_I(+2,-1);
00053 double xi1 = s0*vil_I(-1,+0) + s1*vil_I(+0,+0) + s2*vil_I(+1,+0) + s3*vil_I(+2,+0);
00054 double xi2 = s0*vil_I(-1,+1) + s1*vil_I(+0,+1) + s2*vil_I(+1,+1) + s3*vil_I(+2,+1);
00055 double xi3 = s0*vil_I(-1,+2) + s1*vil_I(+0,+2) + s2*vil_I(+1,+2) + s3*vil_I(+2,+2);
00056
00057 #undef vil_I
00058
00059 double val = 0.25 * ( xi0*t0 + xi1*t1 + xi2*t2 + xi3*t3 );
00060
00061 return val;
00062 }
00063
00064
00065
00066
00067
00068 #ifdef VCL_VC_6
00069 static double vil_bicub_interp_raw_temp_hack = 0.0;
00070 #endif
00071
00072 template<class T>
00073 double vil_bicub_interp_raw(double x, double y, const T* data,
00074 vcl_ptrdiff_t xstep, vcl_ptrdiff_t ystep)
00075 {
00076 int p1x=int(x);
00077 double normx = x-p1x;
00078 int p1y=int(y);
00079 double normy = y-p1y;
00080
00081 const T* pix1 = data + p1y*ystep + p1x*xstep;
00082
00083
00084
00085
00086
00087 if (normx == 0.0 && normy == 0.0) return pix1[0];
00088
00089
00090 double s0=-1.0, s1=-1.0, s2=-1.0, s3=-1.0;
00091 double t0=-1.0, t1=-1.0, t2=-1.0, t3=-1.0;
00092
00093 if (normx != 0.0) {
00094 s0 = ((2-normx)*normx-1)*normx;
00095 s1 = (3*normx-5)*normx*normx+2;
00096 s2 = ((4-3*normx)*normx+1)*normx;
00097 s3 = (normx-1)*normx*normx;
00098 }
00099
00100 if (normy != 0.0) {
00101 t0 = ((2-normy)*normy-1)*normy;
00102 t1 = (3*normy-5)*normy*normy+2;
00103 t2 = ((4-3*normy)*normy+1)*normy;
00104 t3 = (normy-1)*normy*normy;
00105 }
00106
00107 #define vil_I(dx,dy) (pix1[(dx)*xstep+(dy)*ystep])
00108
00109 if (normy == 0.0) {
00110 double val = 0.0;
00111 val += s0*vil_I(-1,+0);
00112 val += s1*vil_I(+0,+0);
00113 val += s2*vil_I(+1,+0);
00114
00115 #ifdef VCL_VC60
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 vil_bicub_interp_raw_temp_hack = val;
00130 #endif
00131
00132 val += s3*vil_I(+2,+0);
00133 val *= 0.5;
00134 return val;
00135 }
00136
00137 if (normx == 0.0) {
00138
00139
00140
00141 double val = t0*vil_I(+0,-1) + t1*vil_I(+0,+0) + t2*vil_I(+0,+1) + t3*vil_I(+0,+2);
00142 val *= 0.5;
00143 return val;
00144 }
00145
00146 double xi0 = s0*vil_I(-1,-1) + s1*vil_I(+0,-1) + s2*vil_I(+1,-1) + s3*vil_I(+2,-1);
00147 double xi1 = s0*vil_I(-1,+0) + s1*vil_I(+0,+0) + s2*vil_I(+1,+0) + s3*vil_I(+2,+0);
00148 double xi2 = s0*vil_I(-1,+1) + s1*vil_I(+0,+1) + s2*vil_I(+1,+1) + s3*vil_I(+2,+1);
00149 double xi3 = s0*vil_I(-1,+2) + s1*vil_I(+0,+2) + s2*vil_I(+1,+2) + s3*vil_I(+2,+2);
00150
00151 #undef vil_I
00152
00153 double val = 0.25 * ( xi0*t0 + xi1*t1 + xi2*t2 + xi3*t3 );
00154
00155 return val;
00156 }
00157
00158 #define VIL_BICUB_INTERP_INSTANTIATE(T) \
00159 template double \
00160 vil_bicub_interp_unsafe (double x, double y, const T* data, \
00161 vcl_ptrdiff_t xstep, vcl_ptrdiff_t ystep); \
00162 template double \
00163 vil_bicub_interp_raw (double x, double y, const T* data, \
00164 vcl_ptrdiff_t xstep, vcl_ptrdiff_t ystep)
00165
00166 #endif // vil_bicub_interp_txx_