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