vil_sample_profile_bicub.hxx
Go to the documentation of this file.
1 // This is core/vil/vil_sample_profile_bicub.hxx
2 #ifndef vil_sample_profile_bicub_hxx_
3 #define vil_sample_profile_bicub_hxx_
4 //:
5 // \file
6 // \brief Bicubic profile sampling functions for 2D images
7 //
8 // The vil bicub source files were derived from the corresponding
9 // vil bilin files, thus the vil bilin/bicub source files are very
10 // similar. If you modify something in this file, there is a
11 // corresponding bilin file that would likely also benefit from
12 // the same change.
13 
15 #include <vil/vil_bicub_interp.h>
16 
17 //: This function should not be the same in bicub and bilin
18 inline bool vil_profile_bicub_in_image(double x0, double y0,
19  double x1, double y1,
20  const vil_image_view_base& image)
21 {
22  return x0 >= 2
23  && y0 >= 2
24  && x1 >= 2
25  && y1 >= 2
26  && x0+3 <= image.ni()
27  && y0+3 <= image.nj()
28  && x1+3 <= image.ni()
29  && y1+3 <= image.nj();
30 }
31 
32 //: Sample along profile, using safe bicubic interpolation
33 // Profile points are along the line between p0 and p1 (in image co-ordinates).
34 // Vector v is resized to n*np elements, where np=image.n_planes().
35 // v[0]..v[np-1] are the values from point p
36 // Points outside image return zero.
37 template <class imType, class vecType>
38 void vil_sample_profile_bicub(vecType* v,
39  const vil_image_view<imType>& image,
40  double x0, double y0, double dx, double dy,
41  int n)
42 {
43  bool all_in_image = vil_profile_bicub_in_image(x0,y0,x0+(n-1)*dx,y0+(n-1)*dy,image);
44 
45  const unsigned ni = image.ni();
46  const unsigned nj = image.nj();
47  const unsigned np = image.nplanes();
48  const std::ptrdiff_t istep = image.istep();
49  const std::ptrdiff_t jstep = image.jstep();
50  const std::ptrdiff_t pstep = image.planestep();
51  double x=x0;
52  double y=y0;
53  const imType* plane0 = image.top_left_ptr();
54 
55  if (all_in_image)
56  {
57  if (np==1)
58  {
59  for (int k=0;k<n;++k,x+=dx,y+=dy)
60  v[k] = vil_bicub_interp(x,y,plane0,ni,nj,istep,jstep);
61  }
62  else
63  {
64  for (int k=0;k<n;++k,x+=dx,y+=dy)
65  {
66  for (unsigned int p=0;p<np;++p,++v)
67  *v = vil_bicub_interp(x,y,plane0+p*pstep,ni,nj,istep,jstep);
68  }
69  }
70  }
71  else
72  {
73  // Use safe interpolation
74  if (np==1)
75  {
76  for (int k=0;k<n;++k,x+=dx,y+=dy)
77  v[k] = vil_bicub_interp_safe(x,y,plane0,ni,nj,istep,jstep);
78  }
79  else
80  {
81  for (int k=0;k<n;++k,x+=dx,y+=dy)
82  {
83  for (unsigned int p=0;p<np;++p,++v)
84  *v = vil_bicub_interp_safe(x,y,plane0+p*pstep,ni,nj,istep,jstep);
85  }
86  }
87  }
88 }
89 
90 #define VIL_SAMPLE_PROFILE_BICUB_INSTANTIATE( imType, vecType ) \
91 template void vil_sample_profile_bicub(vecType* v, \
92  const vil_image_view<imType >& image, \
93  double x0, double y0, \
94  double dx, double dy, \
95  int n)
96 
97 #endif // vil_sample_profile_bicub_hxx_
An abstract base class of smart pointers to actual image data in memory.
Bicubic profile sampling functions for 2D images.
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
Bicubic interpolation functions for 2D images.
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
unsigned nj() const
Height.
#define v
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
double vil_bicub_interp(const vil_image_view< T > &view, double x, double y, unsigned p=0)
Compute bicubic interpolation at (x,y), with minimal bound checks.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
bool vil_profile_bicub_in_image(double x0, double y0, double x1, double y1, const vil_image_view_base &image)
This function should not be the same in bicub and bilin.
double vil_bicub_interp_safe(const vil_image_view< T > &view, double x, double y, unsigned p=0)
Compute bicubic interpolation at (x,y), with bound checks.
unsigned nplanes() const
Number of planes.
void vil_sample_profile_bicub(vecType *v, const vil_image_view< imType > &image, double x0, double y0, double dx, double dy, int n)
Sample along profile, using bicubic interpolation.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.