contrib/brl/bseg/bbgm/bbgm_update.h
Go to the documentation of this file.
00001 // This is brl/bseg/bbgm/bbgm_update.h
00002 #ifndef bbgm_update_h_
00003 #define bbgm_update_h_
00004 //:
00005 // \file
00006 // \brief Update wrappers for distribution images
00007 // \author Matt Leotta (mleotta@lems.brown.edu)
00008 // \date October 3, 2005
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   Apr 21, 2009  MJL  Update to work with vpdt
00013 // \endverbatim
00014 
00015 #include <vil/vil_image_view.h>
00016 
00017 #include <vcl_cassert.h>
00018 #include <vpdl/vpdt/vpdt_field_traits.h>
00019 
00020 #include "bbgm_planes_to_sample.h"
00021 #include "bbgm_image_of.h"
00022 
00023 //: Update with no data
00024 template <class dist_, class updater_>
00025 void update(bbgm_image_of<dist_>& dimg,
00026             const updater_& updater)
00027 {
00028   for (typename bbgm_image_of<dist_>::iterator itr = dimg.begin();
00029        itr != dimg.end(); ++itr)
00030     updater(*itr);
00031 }
00032 
00033 //: Update with a new sample image
00034 template <class dist_, class T, class updater_>
00035 void update(bbgm_image_of<dist_>& dimg,
00036             const vil_image_view<T>& image,
00037             const updater_& updater)
00038 {
00039   typedef typename updater_::field_type F;
00040   assert(dimg.ni() == image.ni());
00041   assert(dimg.nj() == image.nj());
00042   assert(vpdt_field_traits<F>::dimension == image.nplanes());
00043 
00044   const unsigned ni = image.ni();
00045   const unsigned nj = image.nj();
00046 
00047   const vcl_ptrdiff_t planestep = image.planestep();
00048   const vcl_ptrdiff_t istep = image.istep();
00049   const vcl_ptrdiff_t jstep = image.jstep();
00050 
00051   typename bbgm_image_of<dist_>::iterator itr = dimg.begin();
00052   const T* row = image.top_left_ptr();
00053   for (unsigned int j=0; j<nj; ++j, row+=jstep){
00054     const T* col = row;
00055     for (unsigned int i=0; i<ni; ++i, col+=istep, ++itr){
00056       const T* data = col;
00057       F sample;
00058       bbgm_planes_to_sample<T,F,vpdt_field_traits<F>::dimension>::apply(data,sample,planestep);
00059       updater(*itr,sample);
00060     }
00061   }
00062 }
00063 
00064 
00065 //: Update with a new sample image only where mask(i,j)
00066 template <class dist_, class T, class updater_>
00067 void update_masked(bbgm_image_of<dist_>& dimg,
00068                    const vil_image_view<T>& image,
00069                    const updater_& updater,
00070                    const vil_image_view<bool>& mask)
00071 {
00072   typedef typename updater_::field_type F;
00073   assert(dimg.ni() == image.ni());
00074   assert(dimg.nj() == image.nj());
00075   assert(dimg.ni() == mask.ni());
00076   assert(dimg.nj() == mask.nj());
00077   assert(vpdt_field_traits<F>::dimension == image.nplanes());
00078 
00079   const unsigned ni = image.ni();
00080   const unsigned nj = image.nj();
00081 
00082   const vcl_ptrdiff_t planestep = image.planestep();
00083   const vcl_ptrdiff_t istep = image.istep();
00084   const vcl_ptrdiff_t jstep = image.jstep();
00085   const vcl_ptrdiff_t m_istep = mask.istep();
00086   const vcl_ptrdiff_t m_jstep = mask.jstep();
00087 
00088   typename bbgm_image_of<dist_>::iterator itr = dimg.begin();
00089   const bool* m_row = mask.top_left_ptr();
00090   const T* row = image.top_left_ptr();
00091   for (unsigned int j=0; j<nj; ++j, row+=jstep, m_row+=m_jstep){
00092     const T* col = row;
00093     const bool* m_col = m_row;
00094     for (unsigned int i=0; i<ni; ++i, col+=istep, m_col+=m_istep, ++itr){
00095       if (*m_col) {
00096         const T* data = col;
00097         F sample;
00098         bbgm_planes_to_sample<T,F,vpdt_field_traits<F>::dimension>::apply(data,sample,planestep);
00099         updater(*itr,sample);
00100       }
00101     }
00102   }
00103 }
00104 
00105 
00106 #endif // bbgm_update_h_