contrib/mul/mfpf/mfpf_sample_region.h
Go to the documentation of this file.
00001 #ifndef mfpf_sample_region_h_
00002 #define mfpf_sample_region_h_
00003 
00004 //:
00005 // \file
00006 // \brief Sample vector from image, assuming istep==np, pstep=1
00007 // \author Tim Cootes
00008 
00009 #include <mbl/mbl_chord.h>
00010 #include <vnl/vnl_vector.h>
00011 #include <vcl_vector.h>
00012 #include <vcl_cstddef.h> // for std::ptrdiff_t
00013 
00014 //: Sample vector from image, assuming istep==np, pstep=1
00015 //  Assumes vector already correct size, and region completely
00016 //  within image.  Assumes vec has been sized to np*n_pixels.
00017 template <class T>
00018 inline void mfpf_sample_region(const T* image,
00019                                vcl_ptrdiff_t jstep, unsigned np,
00020                                const vcl_vector<mbl_chord>& roi,
00021                                vnl_vector<double>& vec)
00022 {
00023   double *v = vec.data_block();
00024   vcl_vector<mbl_chord>::const_iterator c=roi.begin();
00025   for (;c!=roi.end();++c)
00026   {
00027     const T* im_row  = image+c->y()*jstep;
00028     const T* pix     = im_row + c->start_x()*np;
00029     const T* pix_end = im_row+(c->end_x()+1)*np;
00030     for (;pix!=pix_end;++pix,++v) *v=double(*pix);
00031   }
00032 }
00033 
00034 #endif // #define mfpf_sample_region_h_