contrib/mul/vimt3d/vimt3d_sample_profile_trilin.h
Go to the documentation of this file.
00001 #ifndef vimt3d_sample_profile_trilin_h_
00002 #define vimt3d_sample_profile_trilin_h_
00003 //:
00004 // \file
00005 // \brief Profile sampling functions for 3D images
00006 // \author Tim Cootes
00007 
00008 #include <vimt3d/vimt3d_image_3d_of.h>
00009 #include <vil3d/vil3d_sample_profile_trilin.h>
00010 #include <vnl/vnl_vector.h>
00011 #include <vgl/vgl_point_3d.h>
00012 #include <vgl/vgl_vector_3d.h>
00013 
00014 //: Sample along profile, using trilinear interpolation
00015 //  Profile points are p+iu, where i=[0..n-1] (world co-ordinates).
00016 //  Vector v is resized to n*np elements, where np=image.n_planes().
00017 //  v[0]..v[np-1] are the values from point p
00018 //  Samples outside the image are set to zero.
00019 template <class imType, class vecType>
00020 void vimt3d_sample_profile_trilin(
00021   vnl_vector<vecType>& vec,
00022   const vimt3d_image_3d_of<imType>& image,
00023   const vgl_point_3d<double>& p0,
00024   const vgl_vector_3d<double>& u,
00025   int n)
00026 {
00027   vgl_point_3d<double> im_p0 = image.world2im()(p0);
00028   vgl_point_3d<double> im_p1 = image.world2im()(p0+u);
00029   int np = image.image().nplanes();
00030   vec.set_size(n*np);
00031   vecType *v = vec.data_block();
00032 
00033   // Can do all work in image co-ordinates under an affine transformation
00034   double dx = (im_p1.x()-im_p0.x());
00035   double dy = (im_p1.y()-im_p0.y());
00036   double dz = (im_p1.z()-im_p0.z());
00037 
00038   // Sample along profile between im_p0 and im_p1
00039   vil3d_sample_profile_trilin(v,image.image(),
00040                               im_p0.x(),im_p0.y(),im_p0.z(),dx,dy,dz,n);
00041 }
00042 
00043 
00044 //: Sample along profile, using trilinear interpolation
00045 //  Profile points are p+iu, where i=[0..n-1] (world co-ordinates).
00046 //  Vector v is resized to n*np elements, where np=image.n_planes().
00047 //  v[0]..v[np-1] are the values from point p
00048 //  Samples outside the image are set to the nearest voxel.
00049 template <class imType, class vecType>
00050 void vimt3d_sample_profile_trilin_extend(
00051   vnl_vector<vecType>& vec,
00052   const vimt3d_image_3d_of<imType>& image,
00053   const vgl_point_3d<double>& p0,
00054   const vgl_vector_3d<double>& u,
00055   int n)
00056 {
00057   vgl_point_3d<double> im_p0 = image.world2im()(p0);
00058   vgl_point_3d<double> im_p1 = image.world2im()(p0+u);
00059   int np = image.image().nplanes();
00060   vec.set_size(n*np);
00061   vecType *v = vec.data_block();
00062 
00063   // Can do all work in image co-ordinates under an affine transformation
00064   double dx = (im_p1.x()-im_p0.x());
00065   double dy = (im_p1.y()-im_p0.y());
00066   double dz = (im_p1.z()-im_p0.z());
00067 
00068   // Sample along profile between im_p0 and im_p1
00069   vil3d_sample_profile_trilin_extend(v, image.image(),
00070                                      im_p0.x(),im_p0.y(),im_p0.z(),dx,dy,dz,n);
00071 }
00072 
00073 //: Sample along profile, using trilinear interpolation
00074 //  Profile points are p+iu, where i=[0..n-1] (world co-ordinates).
00075 //  Vector v is resized to n*np elements, where np=image.n_planes().
00076 //  v[0]..v[np-1] are the values from point p
00077 //  Samples outside the image are set NA.
00078 template <class imType, class vecType>
00079 void vimt3d_sample_profile_trilin_edgena(
00080   vnl_vector<vecType>& vec,
00081   const vimt3d_image_3d_of<imType>& image,
00082   const vgl_point_3d<double>& p0,
00083   const vgl_vector_3d<double>& u,
00084   int n)
00085 {
00086   vgl_point_3d<double> im_p0 = image.world2im()(p0);
00087   vgl_point_3d<double> im_p1 = image.world2im()(p0+u);
00088   int np = image.image().nplanes();
00089   vec.set_size(n*np);
00090   vecType *v = vec.data_block();
00091 
00092   // Can do all work in image co-ordinates under an affine transformation
00093   double dx = (im_p1.x()-im_p0.x());
00094   double dy = (im_p1.y()-im_p0.y());
00095   double dz = (im_p1.z()-im_p0.z());
00096 
00097   // Sample along profile between im_p0 and im_p1
00098   vil3d_sample_profile_trilin_edgena(v, image.image(),
00099                                      im_p0.x(),im_p0.y(),im_p0.z(),dx,dy,dz,n);
00100 }
00101 
00102 #endif // vimt3d_sample_profile_trilin_h_