00001
00002 #ifndef vipl_filter_h_
00003 #define vipl_filter_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "vipl_filter_abs.h"
00023 #include <vipl/filter/vipl_trivial_pixeliter.h>
00024
00025 template < class ImgIn, class ImgOut, class DataIn, class DataOut, int Arity, class PixelItr = vipl_trivial_pixeliter >
00026 class vipl_filter ;
00027
00028 #include <vipl/section/vipl_section_descriptor.h>
00029 #include <vipl/section/vipl_section_container.h>
00030
00031 #include <vcl_stlfwd.h>
00032
00033 #ifdef USE_NAMED_ACCESSORS // cannot have both set,
00034 #undef USE_OPERATOR_ACCESSORS // to be safe if we have named we undefine operator()
00035 #else
00036 #ifndef USE_OPERATOR_ACCESSORS // if neither is set
00037 #define USE_NAMED_ACCESSORS // use names by default
00038 #endif
00039 #endif
00040
00041 #ifndef GET_NAME
00042 #define GET_NAME get_pixel
00043 #endif
00044 #ifndef SET_NAME
00045 #define SET_NAME set_pixel
00046 #endif
00047 #ifndef FGET_NAME
00048 #define FGET_NAME fget_pixel
00049 #endif
00050 #ifndef FSET_NAME
00051 #define FSET_NAME fset_pixel
00052 #endif
00053 #ifdef USE_OPERATOR_ACCESSORS
00054
00055 #ifndef GET_PIXEL
00056 #define GET_PIXEL(img,x,y) (img)(x,y)
00057 #endif
00058 #ifndef SET_PIXEL
00059 #define SET_PIXEL(img,x,y,expr) (img)(x,y) = expr
00060 #endif
00061 #ifndef FGET_PIXEL
00062 #define FGET_PIXEL(img,x,y) (img)(x,y)
00063 #endif
00064 #ifndef FSET_PIXEL
00065 #define FSET_PIXEL(img,x,y,expr) (img)(x,y) = expr
00066 #endif
00067 #else // USE_NAMED_ACCESSORS
00068 #ifndef GET_PIXEL
00069 #define GET_PIXEL(img,x,y) (img). GET_NAME (x,y)
00070 #endif
00071 #ifndef SET_PIXEL
00072 #define SET_PIXEL(img,x,y,expr) (img). SET_NAME (expr, x,y)
00073 #endif
00074 #ifndef FGET_PIXEL
00075 #define FGET_PIXEL(img,x,y) (img). FGET_NAME (x,y)
00076 #endif
00077 #ifndef FSET_PIXEL
00078 #define FSET_PIXEL(img,x,y,expr) (img). FSET_NAME (expr, x,y)
00079 #endif
00080 #endif // end use NAMED ACCESSORS
00081
00082 #ifndef CONVERT_TO_OUT
00083 #define CONVERT_TO_OUT(v) ((DataOut) (v))
00084 #endif
00085
00086 #include "vipl_filter_helper.h"
00087
00088 class vipl_trivial_pixeliter;
00089 extern const void * DAhelp(vipl_trivial_pixeliter const*,int level=0);
00090
00091 template < class ImgIn, class ImgOut, class DataIn, class DataOut, int Arity, class PixelItr >
00092 class vipl_filter : public vipl_filter_abs
00093 {
00094
00095 static const VIPL_FILTER_STATE Not_Ready VCL_STATIC_CONST_INIT_INT_DECL(0);
00096 static const VIPL_FILTER_STATE Ready VCL_STATIC_CONST_INIT_INT_DECL(1);
00097 static const VIPL_FILTER_STATE Unchanged VCL_STATIC_CONST_INIT_INT_DECL(2);
00098 static const VIPL_FILTER_STATE Filter_Owned VCL_STATIC_CONST_INIT_INT_DECL(4);
00099
00100
00101 public: typedef typename PixelItr::Titerator Titerator;
00102 public: typedef typename PixelItr::Yiterator Yiterator;
00103 public: typedef typename PixelItr::Xiterator Xiterator;
00104 public: typedef typename PixelItr::Ziterator Ziterator;
00105 public: typedef vipl_filter_abs parent;
00106 public: typedef ImgIn const* inimagept;
00107 public: typedef ImgOut* outimagept;
00108 public: typedef vipl_filter thisclass;
00109
00110
00111
00112 private: int hsimage_border_size;
00113 public: int image_border_size() const { return hsimage_border_size; }
00114 public: int & ref_image_border_size() { return hsimage_border_size; }
00115
00116
00117
00118 private: DataOut hsdef_fill_value;
00119 public: DataOut def_fill_value() const { return hsdef_fill_value; }
00120 public: DataOut & ref_def_fill_value() { return hsdef_fill_value; }
00121
00122
00123 private: VIPL_FILTER_STATE hsinput_state;
00124 public: VIPL_FILTER_STATE input_state() const { return hsinput_state; }
00125 public: VIPL_FILTER_STATE & ref_input_state() { return hsinput_state; }
00126 private: VIPL_FILTER_STATE hsfilter_state;
00127 public: VIPL_FILTER_STATE filter_state() const { return hsfilter_state; }
00128 public: VIPL_FILTER_STATE & ref_filter_state() { return hsfilter_state; }
00129 private: VIPL_FILTER_STATE hsoutput_state;
00130 public: VIPL_FILTER_STATE output_state() const { return hsoutput_state; }
00131 public: VIPL_FILTER_STATE & ref_output_state() { return hsoutput_state; }
00132 public: void put_output_state(VIPL_FILTER_STATE const t) { hsoutput_state = t; }
00133
00134 private: int hsnuminputs;
00135 public: int numinputs() const { return hsnuminputs; }
00136 public: int & ref_numinputs() { return hsnuminputs; }
00137
00138 private: int hsnumoutputs;
00139 public: int numoutputs() const { return hsnumoutputs; }
00140 public: int & ref_numoutputs() { return hsnumoutputs; }
00141
00142 private: vcl_vector<inimagept> hsinf;
00143 public: vcl_vector<inimagept> inf() const { return hsinf; }
00144 public: vcl_vector<inimagept> & ref_inf() { return hsinf; }
00145
00146
00147 private: outimagept hsoutf;
00148 public: outimagept outf() const { return hsoutf; }
00149 public: outimagept & ref_outf() { return hsoutf; }
00150 public: void put_outf(outimagept const& t) { hsoutf = t; }
00151
00152
00153 typedef vipl_section_container< DataIn >* in_section_type;
00154 private: in_section_type hssrc_section;
00155 public: in_section_type src_section() const { return hssrc_section; }
00156 public: in_section_type & ref_src_section() { return hssrc_section; }
00157
00158 typedef vipl_section_descriptor< DataIn >* in_descriptor_type;
00159 private: in_descriptor_type hsinsecp;
00160 public: in_descriptor_type insecp() const { return hsinsecp; }
00161 public: in_descriptor_type & ref_insecp() { return hsinsecp; }
00162 public: void put_insecp(in_descriptor_type const t) { hsinsecp = t; }
00163
00164 typedef vipl_section_container< DataOut >* out_section_type;
00165 private: out_section_type hsdst_section;
00166 public: out_section_type dst_section() const { return hsdst_section; }
00167 public: out_section_type & ref_dst_section() { return hsdst_section; }
00168
00169 typedef vipl_section_descriptor< DataOut>* out_descriptor_type;
00170 private: out_descriptor_type hssecp;
00171 public: out_descriptor_type secp() const { return hssecp; }
00172 public: out_descriptor_type & ref_secp() { return hssecp; }
00173 public: void put_secp(out_descriptor_type t) { hssecp = t; }
00174
00175 typedef vipl_section_descriptor< DataIn >* in_ROA_descriptor_type;
00176 private: in_ROA_descriptor_type hsinROA;
00177 public: in_ROA_descriptor_type inROA() const { return hsinROA; }
00178 public: in_ROA_descriptor_type & ref_inROA() { return hsinROA; }
00179
00180 typedef vipl_section_descriptor< DataOut >* out_ROA_descriptor_type;
00181 private: out_ROA_descriptor_type hsROA;
00182 public: out_descriptor_type ROA() const { return hsROA; }
00183 public: out_descriptor_type & ref_ROA() { return hsROA; }
00184
00185
00186 private: bool hsis_input_driven;
00187 public: bool is_input_driven() const { return hsis_input_driven; }
00188 public: bool & ref_is_input_driven() { return hsis_input_driven; }
00189 public: void put_is_input_driven(bool b=true) { hsis_input_driven=b; }
00190
00191 public:
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 vipl_filter(ImgIn const* src_img,
00203 ImgOut* dst_img=0,
00204 int ninputs=1,
00205 int img_border=0 ,
00206 DataOut fill_val=0 ) ;
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 vipl_filter(ImgIn const** src_img,
00218 ImgOut* dst_img=0,
00219 int ninputs=1,
00220 int img_border=0 ,
00221 DataOut fill_val=0 );
00222 virtual ~vipl_filter();
00223 vipl_filter();
00224 vipl_filter(vipl_filter< ImgIn, ImgOut, DataIn, DataOut, Arity, PixelItr > const&);
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 virtual bool filter();
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 bool process(ImgIn const& inimg, ImgOut& outimg);
00250
00251 bool process(ImgIn const* inimg, ImgOut* outimg);
00252
00253
00254
00255
00256
00257
00258
00259 int start(int axis) const;
00260 int start(int axis, int other_axis_value) const;
00261
00262
00263
00264
00265
00266
00267
00268 int stop(int axis) const;
00269 int stop(int axis, int other_axis_value) const;
00270
00271
00272
00273
00274
00275
00276
00277 int start_src(int axis) const;
00278
00279
00280
00281
00282
00283
00284
00285 int stop_src(int axis) const;
00286
00287
00288
00289
00290
00291
00292
00293 int start_dst(int axis) const;
00294
00295
00296
00297
00298
00299
00300
00301 int stop_dst(int axis) const;
00302
00303
00304
00305
00306
00307
00308 bool put_in_data_ptr(ImgIn const* fpointer, int index=0);
00309
00310
00311
00312
00313 inimagept in_data_ptr( int index=0);
00314
00315
00316
00317
00318 const ImgIn& in_data( int index=0) const ;
00319
00320
00321
00322
00323
00324 bool put_out_data_ptr(ImgOut* fpointer, int =0);
00325
00326
00327
00328
00329 virtual outimagept out_data_ptr(int index=0);
00330
00331
00332
00333 virtual ImgOut& out_data(int index=0) const;
00334
00335 protected:
00336
00337
00338
00339
00340
00341
00342 virtual bool preop();
00343
00344
00345
00346
00347
00348 virtual bool postop();
00349
00350
00351
00352
00353 virtual bool applyop() = 0;
00354
00355
00356
00357
00358
00359 virtual bool section_preop();
00360
00361
00362
00363
00364 virtual bool section_postop();
00365
00366
00367
00368
00369
00370 virtual bool section_applyop() = 0;
00371
00372
00373
00374
00375 virtual bool ptr_based_section_applyop();
00376
00377
00378
00379
00380
00381
00382 virtual bool check_params_1(bool& proceed_on_warn) const ;
00383
00384 public:
00385
00386
00387
00388
00389 virtual bool is_ready() const;
00390
00391
00392
00393
00394
00395 int is_section_within_ROA( int axis) const;
00396
00397 #ifdef USE_COMPOSE_WITH
00398
00399
00400
00401
00402
00403
00404 bool compose_with( vipl_filter_abs& to);
00405 #endif
00406
00407 };
00408
00409 #ifdef INSTANTIATE_TEMPLATES
00410 #include "vipl_filter.txx"
00411 #endif
00412
00413 #endif // file guard