contrib/tbl/vipl/filter/vipl_filter_2d.txx

Go to the documentation of this file.
00001 // This is tbl/vipl/filter/vipl_filter_2d.txx
00002 #ifndef vipl_filter_2d_txx_
00003 #define vipl_filter_2d_txx_
00004 
00005 #include "vipl_filter_2d.h"
00006 #include <vcl_compiler.h>
00007 
00008 // Main constructor for this abstract class. If dst_image
00009 // (by default) the output will be generated automatically when
00010 // filtering is about to proceed. (Either way, the filter
00011 // decrements the refcount of the output when it is destroyed.)
00012 // Some filters support multiple inputs, if ninputs is >1 then
00013 // this constructor expects src_img to be the first element
00014 // pointer to the input (i.e. src_img+1 is the location of input
00015 // image2). Note that the filter keeps pointers to the input
00016 // (properly refcounted). Actually the main filter constructor
00017 // does all the work
00018 template < class ImgIn,class ImgOut,class DataIn,class DataOut, class PixelItr >
00019   vipl_filter_2d< ImgIn,ImgOut,DataIn,DataOut,PixelItr >
00020   ::vipl_filter_2d(const ImgIn* src_img ,
00021                    ImgOut* dst_img ,
00022                    int ninputs,
00023                    int img_border ,
00024                    DataOut fill_val)
00025     : vipl_filter<ImgIn, ImgOut, DataIn, DataOut, 2 VCL_DFL_TMPL_ARG(vipl_trivial_pixeliter)>
00026       (src_img, dst_img, ninputs, img_border, fill_val)
00027 {}
00028 
00029 // A second the workhorse constructor for this class. If dst_img is null (by
00030 // default), the output will be generated automatically when filtering is
00031 // about to proceed. The filter decrements the refcount of the output when it
00032 // is destroyed. Some filters support multiple inputs, if ninputs is >1 then
00033 // this constructor uses non_consecutive input images (with their address in a
00034 // c_vector, i.e. *(src_img+1) is the location of input image2). Note that
00035 // the filter keeps pointers to the input (properly refcounted). Actually the
00036 // main filter constructor does all the work
00037 template < class ImgIn,class ImgOut,class DataIn,class DataOut, class PixelItr >
00038   vipl_filter_2d< ImgIn,ImgOut,DataIn,DataOut,PixelItr > ::vipl_filter_2d(
00039                 const ImgIn** src_img ,
00040                 ImgOut* dst_img ,
00041                 int ninputs,
00042                 int img_border ,
00043                 DataOut fill_val)
00044      : vipl_filter<ImgIn, ImgOut, DataIn, DataOut, 2 VCL_DFL_TMPL_ARG(vipl_trivial_pixeliter)>
00045        (src_img, dst_img, ninputs, img_border, fill_val)
00046 {}
00047 
00048 template < class ImgIn,class ImgOut,class DataIn,class DataOut, class PixelItr >
00049   vipl_filter_2d< ImgIn,ImgOut,DataIn,DataOut,PixelItr >
00050   ::vipl_filter_2d(const vipl_filter_2d< ImgIn,ImgOut,DataIn,DataOut,PixelItr > &t)
00051   :
00052   vipl_filter< ImgIn, ImgOut, DataIn, DataOut, 2 VCL_DFL_TMPL_ARG(vipl_trivial_pixeliter)> (t)
00053 // C++ special low-level copy constructor
00054 {}
00055 
00056 // This is the method that walks over the sections calling
00057 // section_applyop. Now that we know the dim we can write the loop...
00058 template < class ImgIn,class ImgOut,class DataIn,class DataOut, class PixelItr >
00059   bool vipl_filter_2d< ImgIn,ImgOut,DataIn,DataOut,PixelItr > ::applyop()
00060 {
00061   typedef typename vipl_section_container< DataIn  >::iterator iter_in;
00062   typedef typename vipl_section_container< DataOut >::iterator iter_out;
00063 
00064   // assuming that the coordinate space of input, intermediate and output are
00065   // "locked" by sectioning
00066   if (!this->ref_outf()) {
00067     vcl_cerr << "Warning: empty output image in vipl_filter_2d::applyop, returning without processing\n";
00068     return false;
00069   }
00070   // the name of the section container generator.
00071   // do not generate a new one if there is one already.
00072   if (!this->ref_dst_section()) {
00073     this->ref_dst_section() = vipl_filterable_section_container_generator(*this->ref_outf(),(DataOut*)0);
00074   }
00075   if (!this->ref_dst_section()) {
00076     vcl_cerr << "Warning: empty dst section in vipl_filter_2d::applyop, returning without processing\n";
00077     return false;
00078   }
00079   if (!this->ref_src_section()) {
00080     this->ref_src_section() = vipl_filterable_section_container_generator(*this->ref_inf()[0],(DataIn*)0);
00081   }
00082   if (!this->ref_src_section()) {
00083     vcl_cerr << "Warning: empty src section in vipl_filter_2d::applyop, presuming output driving but cannot be ptr safe\n";
00084   }
00085   this->preop(); // virtual function call
00086   this->ref_dst_section()->ref_overlap()[0] = this->image_border_size();
00087   this->ref_dst_section()->ref_overlap()[1] = this->image_border_size();
00088   if (this->ref_src_section()) {
00089     this->ref_src_section()->ref_overlap()[0] = this->image_border_size();
00090     this->ref_src_section()->ref_overlap()[1] = this->image_border_size();
00091   }
00092   iter_out enddstitr, dstitr;
00093   iter_in endsrcitr, srcitr;
00094   if (this->ref_src_section()) {
00095     endsrcitr = (*this->ref_src_section()).end();
00096     srcitr = (*this->ref_src_section()).begin();
00097   }
00098   if (this->ref_dst_section()) {
00099     enddstitr = (*this->ref_dst_section()).end();
00100     dstitr = (*this->ref_dst_section()).begin();
00101   }
00102   if (this->is_input_driven())
00103   {
00104     iter_in enditr = (*this->ref_src_section()).end();
00105     for (iter_in it = (*this->ref_src_section()).begin(); it != enditr; ++it)
00106     {
00107       if (dstitr ==enddstitr) {
00108         vcl_cerr << "Warning: In vipl_filter_2d, output iter ran out of items before input.  resetting to beginning\n";
00109         dstitr = (*this->ref_dst_section()).begin();
00110       }
00111 #ifdef VCL_VC_6 // this awkward construction is to get around a VC60 compiler bug
00112       vipl_section_descriptor<DataOut>& secDesc = *dstitr;
00113       put_secp( new vipl_section_descriptor<DataOut> (secDesc) );
00114 #else
00115       put_secp( new vipl_section_descriptor<DataOut> (*dstitr));
00116 #endif
00117       this->ref_dst_section()->ref_overlap()[0] = this->image_border_size();
00118       this->ref_dst_section()->ref_overlap()[1] = this->image_border_size();
00119       if (this->ref_src_section()) {
00120 #ifdef VCL_VC_6 // this awkward construction is to get around a VC60 compiler bug
00121         vipl_section_descriptor<DataIn>& inSecDesc = *it;
00122         put_insecp( new vipl_section_descriptor<DataIn> (inSecDesc));
00123 #else
00124         put_insecp( new vipl_section_descriptor<DataIn> (*it));
00125 #endif
00126         this->ref_src_section()->ref_overlap()[0] = this->image_border_size();
00127         this->ref_src_section()->ref_overlap()[1] = this->image_border_size();
00128       }
00129       this->section_preop(); // virtual function call
00130       this->section_applyop(); // virtual function call
00131       this->section_postop(); // virtual function call
00132       if (this->ref_secp()) {
00133         FILTER_IMPTR_DEC_REFCOUNT(this->ref_secp()); // ??really what we want or a kludge??
00134         ++dstitr;
00135       }
00136       if (this->ref_insecp()) {
00137         FILTER_IMPTR_DEC_REFCOUNT(this->ref_insecp());
00138       }
00139     }
00140   }
00141   else
00142   {
00143     iter_out enditr = (*this->ref_dst_section()).end();
00144     for (iter_out it = (*this->ref_dst_section()).begin(); it != enditr; ++it)
00145     {
00146       if (srcitr == endsrcitr) {
00147         vcl_cerr << "Warning: In vipl_filter_2d, input iter ran out of items before output.  resetting to beginning\n";
00148         srcitr = (*this->ref_src_section()).begin();
00149       }
00150 #ifdef VCL_VC_6 // this awkward construction is to get around a VC60 compiler bug
00151       vipl_section_descriptor<DataOut>& secDesc2 = *it;
00152       put_secp( new vipl_section_descriptor<DataOut> (secDesc2));
00153 #else
00154       put_secp( new vipl_section_descriptor<DataOut> (*it));
00155 #endif
00156       this->ref_dst_section()->ref_overlap()[0] = this->image_border_size();
00157       this->ref_dst_section()->ref_overlap()[1] = this->image_border_size();
00158       if (this->ref_src_section()) {
00159 #ifdef VCL_VC_6 // this awkward construction is to get around a VC60 compiler bug
00160         vipl_section_descriptor<DataIn>& inSecDesc2 = *srcitr;
00161         put_insecp( new vipl_section_descriptor<DataIn> (inSecDesc2));
00162 #else
00163         put_insecp( new vipl_section_descriptor<DataIn> (*srcitr));
00164 #endif
00165         this->ref_src_section()->ref_overlap()[0] = this->image_border_size();
00166         this->ref_src_section()->ref_overlap()[1] = this->image_border_size();
00167       }
00168       this->section_preop(); // virtual function call
00169       this->section_applyop(); // virtual function call
00170       this->section_postop(); // virtual function call
00171       if (this->ref_secp()) {
00172         FILTER_IMPTR_DEC_REFCOUNT(this->ref_secp()); // ??really what we want or a kludge??
00173       }
00174       if (this->ref_insecp()) {
00175         FILTER_IMPTR_DEC_REFCOUNT(this->ref_insecp());
00176         ++srcitr;
00177       }
00178     }
00179   }
00180   this->postop(); // virtual function call
00181   return true;
00182 }
00183 
00184 #endif // vipl_filter_2d_txx_

Generated on Mon Oct 6 05:13:19 2008 for contrib/tbl/vipl by  doxygen 1.5.1