00001
00002 #ifndef vil3d_algo_convolve_1d_h_
00003 #define vil3d_algo_convolve_1d_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <vcl_cassert.h>
00016 #include <vil/algo/vil_convolve_1d.h>
00017 #include <vil3d/vil3d_image_view.h>
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 template <class srcT, class destT, class kernelT, class accumT>
00041 inline void vil3d_convolve_1d(const vil3d_image_view<srcT>& src_im,
00042 vil3d_image_view<destT>& dest_im,
00043 const kernelT* kernel,
00044 vcl_ptrdiff_t k_lo, vcl_ptrdiff_t k_hi,
00045 accumT ac,
00046 enum vil_convolve_boundary_option start_option,
00047 enum vil_convolve_boundary_option end_option)
00048 {
00049 const unsigned n_i = src_im.ni(),
00050 n_j = src_im.nj(),
00051 n_k = src_im.nk(),
00052 n_p = src_im.nplanes();
00053 assert(k_hi - k_lo +1 <= (int) n_i);
00054 const vcl_ptrdiff_t s_istep = src_im.istep(),
00055 s_jstep = src_im.jstep(),
00056 s_kstep = src_im.kstep(),
00057 s_pstep = src_im.planestep();
00058
00059 dest_im.set_size(n_i, n_j, n_k, n_p);
00060
00061 const vcl_ptrdiff_t d_istep = dest_im.istep(),
00062 d_jstep = dest_im.jstep(),
00063 d_kstep = dest_im.kstep(),
00064 d_pstep = dest_im.planestep();
00065
00066
00067 const srcT* src_plane = src_im.origin_ptr();
00068 destT* dest_plane = dest_im.origin_ptr();
00069 for (unsigned p=0; p<n_p; ++p, src_plane+=s_pstep, dest_plane+=d_pstep)
00070 {
00071
00072 const srcT* src_slice = src_plane;
00073 destT* dest_slice = dest_plane;
00074 for (unsigned k=0; k<n_k; ++k, src_slice+=s_kstep, dest_slice+=d_kstep)
00075 {
00076
00077
00078 const srcT* src_row = src_slice;
00079 destT* dest_row = dest_slice;
00080
00081 if (s_istep == 1)
00082 {
00083 if (d_istep == 1)
00084 for (unsigned int j=0; j<n_j; ++j, src_row+=s_jstep, dest_row+=d_jstep)
00085 vil_convolve_1d(src_row, n_i, 1, dest_row, 1,
00086 kernel, k_lo, k_hi, ac, start_option, end_option);
00087 else
00088 for (unsigned int j=0; j<n_j; ++j, src_row+=s_jstep, dest_row+=d_jstep)
00089 vil_convolve_1d(src_row, n_i, 1, dest_row, d_istep,
00090 kernel, k_lo, k_hi, ac, start_option, end_option);
00091 }
00092 else
00093 {
00094 if (d_istep == 1)
00095 for (unsigned int j=0; j<n_j; ++j, src_row+=s_jstep, dest_row+=d_jstep)
00096 vil_convolve_1d(src_row, n_i, s_istep, dest_row, 1,
00097 kernel, k_lo, k_hi, ac, start_option, end_option);
00098 else
00099 for (unsigned int j=0; j<n_j; ++j, src_row+=s_jstep, dest_row+=d_jstep)
00100 vil_convolve_1d(src_row, n_i, s_istep, dest_row, d_istep,
00101 kernel, k_lo, k_hi, ac, start_option, end_option);
00102 }
00103 }
00104 }
00105 }
00106
00107 #endif // vil3d_algo_convolve_1d_h_
00108