00001
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
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00030
00031
00032
00033
00034
00035
00036
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
00054 {}
00055
00056
00057
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
00065
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
00071
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();
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
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();
00130 this->section_applyop();
00131 this->section_postop();
00132 if (this->ref_secp()) {
00133 FILTER_IMPTR_DEC_REFCOUNT(this->ref_secp());
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
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();
00169 this->section_applyop();
00170 this->section_postop();
00171 if (this->ref_secp()) {
00172 FILTER_IMPTR_DEC_REFCOUNT(this->ref_secp());
00173 }
00174 if (this->ref_insecp()) {
00175 FILTER_IMPTR_DEC_REFCOUNT(this->ref_insecp());
00176 ++srcitr;
00177 }
00178 }
00179 }
00180 this->postop();
00181 return true;
00182 }
00183
00184 #endif // vipl_filter_2d_txx_