contrib/mul/vimt3d/vimt3d_trilin_interp.h
Go to the documentation of this file.
00001 // This is mul/vimt3d/vimt3d_trilin_interp.h
00002 #ifndef vimt3d_trilin_interp_h_
00003 #define vimt3d_trilin_interp_h_
00004 //:
00005 // \file
00006 // \brief Bilinear interpolation functions for 2D images
00007 // \author Tim Cootes
00008 
00009 #include <vimt3d/vimt3d_image_3d_of.h>
00010 #include <vgl/vgl_point_3d.h>
00011 #include <vil3d/vil3d_trilin_interp.h>
00012 #include <vil3d/vil3d_image_view.h>
00013 
00014 //: Compute trilinear interpolation at p(x,y,z) in world coordinates, with bound checks.
00015 //  Interpolates given plane of image.image() at image.world2im(p).
00016 //  If p is outside interpolatable image region, returns zero or \a outval
00017 template<class T>
00018 inline double vimt3d_trilin_interp_safe(const vimt3d_image_3d_of<T>& image,
00019                                         const vgl_point_3d<double>& p,
00020                                         unsigned plane=0,
00021                                         T outval=0)
00022 {
00023   vgl_point_3d<double> im_p = image.world2im()(p);
00024   const vil3d_image_view<T>& im = image.image();
00025   return vil3d_trilin_interp_safe(im_p.x(),im_p.y(),im_p.z(),
00026                                   im.origin_ptr()+plane*im.planestep(),
00027                                   im.ni(),im.nj(),im.nk(),
00028                                   im.istep(),im.jstep(),im.kstep(),
00029                                   outval);
00030 }
00031 
00032 //: Compute trilinear interpolation at p(x,y,z) in world coordinates, no bound checks.
00033 //  Interpolates given plane of image.image() at image.world2im(p).
00034 template<class T>
00035 inline double vimt3d_trilin_interp_raw(const vimt3d_image_3d_of<T>& image,
00036                                        const vgl_point_3d<double>& p,
00037                                        unsigned plane=0)
00038 {
00039   vgl_point_3d<double> im_p = image.world2im()(p);
00040   const vil3d_image_view<T>& im = image.image();
00041   return vil3d_trilin_interp_raw(im_p.x(),im_p.y(),im_p.z(),
00042                                  im.origin_ptr()+plane*im.planestep(),
00043                                  im.istep(),im.jstep(),im.kstep());
00044 }
00045 
00046 //: Compute trilinear interpolation at p(x,y,z) in world coordinates, using the nearest valid value if out of bounds.
00047 //  Interpolates given plane of image.image() at image.world2im(p).
00048 //  If p is outside safe interpolatable image region, nearest pixel value is returned.
00049 template<class T>
00050 inline double vimt3d_trilin_interp_safe_extend(const vimt3d_image_3d_of<T>& image,
00051                                                const vgl_point_3d<double>& p,
00052                                                unsigned plane=0)
00053 {
00054   vgl_point_3d<double> im_p = image.world2im()(p);
00055   const vil3d_image_view<T>& im = image.image();
00056   return vil3d_trilin_interp_safe_extend(im_p.x(),im_p.y(),im_p.z(),
00057                                          im.origin_ptr()+plane*im.planestep(),
00058                                          im.ni(),im.nj(),im.nk(),
00059                                          im.istep(),im.jstep(),im.kstep());
00060 }
00061 
00062 #endif // vimt3d_trilin_interp_h_