00001
00002 #ifndef vil_sample_profile_bicub_txx_
00003 #define vil_sample_profile_bicub_txx_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "vil_sample_profile_bicub.h"
00015 #include <vil/vil_bicub_interp.h>
00016
00017 inline bool vil_profile_in_image(double x0, double y0,
00018 double x1, double y1,
00019 const vil_image_view_base& image)
00020 {
00021 return x0 >= 2
00022 && y0 >= 2
00023 && x1 >= 2
00024 && y1 >= 2
00025 && x0+3 <= image.ni()
00026 && y0+3 <= image.nj()
00027 && x1+3 <= image.ni()
00028 && y1+3 <= image.nj();
00029 }
00030
00031
00032
00033
00034
00035
00036 template <class imType, class vecType>
00037 void vil_sample_profile_bicub(vecType* v,
00038 const vil_image_view<imType>& image,
00039 double x0, double y0, double dx, double dy,
00040 int n)
00041 {
00042 bool all_in_image = vil_profile_in_image(x0,y0,x0+(n-1)*dx,y0+(n-1)*dy,image);
00043
00044 const unsigned ni = image.ni();
00045 const unsigned nj = image.nj();
00046 const unsigned np = image.nplanes();
00047 const vcl_ptrdiff_t istep = image.istep();
00048 const vcl_ptrdiff_t jstep = image.jstep();
00049 const vcl_ptrdiff_t pstep = image.planestep();
00050 double x=x0;
00051 double y=y0;
00052 const imType* plane0 = image.top_left_ptr();
00053
00054 if (all_in_image)
00055 {
00056 if (np==1)
00057 {
00058 for (int k=0;k<n;++k,x+=dx,y+=dy)
00059 v[k] = vil_bicub_interp(x,y,plane0,ni,nj,istep,jstep);
00060 }
00061 else
00062 {
00063 for (int k=0;k<n;++k,x+=dx,y+=dy)
00064 {
00065 for (unsigned int p=0;p<np;++p,++v)
00066 *v = vil_bicub_interp(x,y,plane0+p*pstep,ni,nj,istep,jstep);
00067 }
00068 }
00069 }
00070 else
00071 {
00072
00073 if (np==1)
00074 {
00075 for (int k=0;k<n;++k,x+=dx,y+=dy)
00076 v[k] = vil_bicub_interp_safe(x,y,plane0,ni,nj,istep,jstep);
00077 }
00078 else
00079 {
00080 for (int k=0;k<n;++k,x+=dx,y+=dy)
00081 {
00082 for (unsigned int p=0;p<np;++p,++v)
00083 *v = vil_bicub_interp_safe(x,y,plane0+p*pstep,ni,nj,istep,jstep);
00084 }
00085 }
00086 }
00087 }
00088
00089 #define VIL_SAMPLE_PROFILE_BICUB_INSTANTIATE( imType, vecType ) \
00090 template void vil_sample_profile_bicub(vecType* v, \
00091 const vil_image_view<imType >& image, \
00092 double x0, double y0, \
00093 double dx, double dy, \
00094 int n)
00095
00096 #endif // vil_sample_profile_bicub_txx_