21 #ifndef mia_core_filter_hh
22 #define mia_core_filter_hh
37 static const char *type_descr;
44 static const char *type_descr;
47 #define DC(T, D) dynamic_cast<const T&>(D)
48 #define DV(T, D) dynamic_cast<T&>(D)
96 typedef std::shared_ptr<TDataFilter<D> >
Pointer;
106 result_type
filter(
const Image& image)
const;
111 result_type
filter(std::shared_ptr<D> pimage)
const;
113 virtual result_type do_filter(
const Image& image)
const = 0;
114 virtual result_type do_filter(std::shared_ptr<D> image)
const;
128 template <
class Image>
143 template <
template <
class>
class D>
145 typedef D<bool> Dbool;
146 typedef D<signed char> Dsc;
147 typedef D<unsigned char> Duc;
148 typedef D<signed short> Dss;
149 typedef D<unsigned short> Dus;
150 typedef D<signed int> Dsi;
151 typedef D<unsigned int> Dui;
153 typedef D<signed long> Dsl;
154 typedef D<unsigned long> Dul;
156 typedef D<float> Dfloat;
157 typedef D<double> Ddouble;
171 template <
typename B>
195 template <
typename F,
typename B>
196 static typename F::result_type
filter(
const F& f,
const B& b)
198 typedef typename Binder<B>::Derived D;
199 switch (b.get_pixel_type()) {
200 case it_bit:
return f(DC(
typename D::Dbool,b));
201 case it_sbyte:
return f(DC(
typename D::Dsc,b));
202 case it_ubyte:
return f(DC(
typename D::Duc,b));
203 case it_sshort:
return f(DC(
typename D::Dss,b));
204 case it_ushort:
return f(DC(
typename D::Dus,b));
205 case it_sint:
return f(DC(
typename D::Dsi,b));
206 case it_uint:
return f(DC(
typename D::Dui,b));
208 case it_slong:
return f(DC(
typename D::Dsl,b));
209 case it_ulong:
return f(DC(
typename D::Dul,b));
211 case it_float:
return f(DC(
typename D::Dfloat,b));
212 case it_double:
return f(DC(
typename D::Ddouble,b));
214 assert(!
"unsupported pixel type in image");
215 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
231 template <
typename F,
typename B>
234 typedef typename Binder<B>::Derived D;
235 switch (b.get_pixel_type()) {
236 case it_bit:
return f(DV(
typename D::Dbool,b));
237 case it_sbyte:
return f(DV(
typename D::Dsc,b));
238 case it_ubyte:
return f(DV(
typename D::Duc,b));
239 case it_sshort:
return f(DV(
typename D::Dss,b));
240 case it_ushort:
return f(DV(
typename D::Dus,b));
241 case it_sint:
return f(DV(
typename D::Dsi,b));
242 case it_uint:
return f(DV(
typename D::Dui,b));
244 case it_slong:
return f(DV(
typename D::Dsl,b));
245 case it_ulong:
return f(DV(
typename D::Dul,b));
247 case it_float:
return f(DV(
typename D::Dfloat,b));
248 case it_double:
return f(DV(
typename D::Ddouble,b));
250 assert(!
"unsupported pixel type in image");
251 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
266 template <
typename F,
typename B>
267 static typename F::result_type
accumulate(F& f,
const B& data)
269 typedef typename Binder<B>::Derived D;
270 switch (data.get_pixel_type()) {
271 case it_bit:
return f(DC(
typename D::Dbool,data));
272 case it_sbyte:
return f(DC(
typename D::Dsc,data));
273 case it_ubyte:
return f(DC(
typename D::Duc,data));
274 case it_sshort:
return f(DC(
typename D::Dss,data));
275 case it_ushort:
return f(DC(
typename D::Dus,data));
276 case it_sint:
return f(DC(
typename D::Dsi,data));
277 case it_uint:
return f(DC(
typename D::Dui,data));
279 case it_slong:
return f(DC(
typename D::Dsl,data));
280 case it_ulong:
return f(DC(
typename D::Dul,data));
282 case it_float:
return f(DC(
typename D::Dfloat,data));
283 case it_double:
return f(DC(
typename D::Ddouble,data));
285 assert(!
"unsupported pixel type in image");
286 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
302 template <
typename F,
typename B>
303 static typename F::result_type
filter_equal(
const F& f,
const B& a,
const B& b)
305 assert(a.get_pixel_type() == b.get_pixel_type());
306 typedef typename Binder<B>::Derived D;
307 switch (a.get_pixel_type()) {
308 case it_bit:
return f(DC(
typename D::Dbool, a), DC(
typename D::Dbool,b));
309 case it_sbyte:
return f( DC(
typename D::Dsc, a), DC(
typename D::Dsc,b));
310 case it_ubyte:
return f( DC(
typename D::Duc, a), DC(
typename D::Duc,b));
311 case it_sshort:
return f( DC(
typename D::Dss, a), DC(
typename D::Dss,b));
312 case it_ushort:
return f( DC(
typename D::Dus, a), DC(
typename D::Dus,b));
313 case it_sint:
return f( DC(
typename D::Dsi, a), DC(
typename D::Dsi,b));
314 case it_uint:
return f( DC(
typename D::Dui, a), DC(
typename D::Dui,b));
316 case it_slong:
return f( DC(
typename D::Dsl, a), DC(
typename D::Dsl,b));
317 case it_ulong:
return f( DC(
typename D::Dul, a), DC(
typename D::Dul,b));
319 case it_float:
return f( DC(
typename D::Dfloat, a), DC(
typename D::Dfloat,b));
320 case it_double:
return f( DC(
typename D::Ddouble, a), DC(
typename D::Ddouble,b));
322 assert(!
"unsupported pixel type in image");
323 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
339 template <
typename F,
typename B>
342 assert(a.get_pixel_type() == b.get_pixel_type());
343 typedef typename Binder<B>::Derived D;
344 switch (a.get_pixel_type()) {
345 case it_bit: f(DC(
typename D::Dbool, a), DV(
typename D::Dbool,b));
break;
346 case it_sbyte: f( DC(
typename D::Dsc, a), DV(
typename D::Dsc,b));
break;
347 case it_ubyte: f( DC(
typename D::Duc, a), DV(
typename D::Duc,b));
break;
348 case it_sshort: f( DC(
typename D::Dss, a), DV(
typename D::Dss,b));
break;
349 case it_ushort: f( DC(
typename D::Dus, a), DV(
typename D::Dus,b));
break;
350 case it_sint: f( DC(
typename D::Dsi, a), DV(
typename D::Dsi,b));
break;
351 case it_uint: f( DC(
typename D::Dui, a), DV(
typename D::Dui,b));
break;
353 case it_slong: f( DC(
typename D::Dsl, a), DV(
typename D::Dsl,b));
break;
354 case it_ulong: f( DC(
typename D::Dul, a), DV(
typename D::Dul,b));
break;
356 case it_float: f( DC(
typename D::Dfloat, a), DV(
typename D::Dfloat,b));
break;
357 case it_double: f( DC(
typename D::Ddouble, a), DV(
typename D::Ddouble,b));
break;
359 assert(!
"unsupported pixel type in image");
360 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
376 template <
typename F,
typename B,
typename O>
379 typedef typename Binder<B>::Derived D;
380 switch (a.get_pixel_type()) {
381 case it_bit:
return f(DC(
typename D::Dbool, a), b);
break;
382 case it_sbyte:
return f(DC(
typename D::Dsc, a), b);
break;
383 case it_ubyte:
return f(DC(
typename D::Duc, a), b);
break;
384 case it_sshort:
return f(DC(
typename D::Dss, a), b);
break;
385 case it_ushort:
return f(DC(
typename D::Dus, a), b);
break;
386 case it_sint:
return f(DC(
typename D::Dsi, a), b);
break;
387 case it_uint:
return f(DC(
typename D::Dui, a), b);
break;
389 case it_slong:
return f(DC(
typename D::Dsl, a), b);
break;
390 case it_ulong:
return f(DC(
typename D::Dul, a), b);
break;
392 case it_float:
return f(DC(
typename D::Dfloat, a), b);
break;
393 case it_double:
return f(DC(
typename D::Ddouble, a), b);
break;
395 assert(!
"unsupported pixel type in image");
396 throw std::invalid_argument(
"mia::filter_and_output: unsupported pixel type in image");
402 template <
typename F,
typename A,
typename B>
403 static typename F::result_type _filter(
const F& f,
const A& a,
const B& b)
405 typedef typename Binder<A>::Derived D;
406 switch (a.get_pixel_type()) {
407 case it_bit:
return f(DC(
typename D::Dbool, a), b);
408 case it_sbyte:
return f(DC(
typename D::Dsc, a), b);
409 case it_ubyte:
return f(DC(
typename D::Duc, a), b);
410 case it_sshort:
return f(DC(
typename D::Dss, a), b);
411 case it_ushort:
return f(DC(
typename D::Dus, a), b);
412 case it_sint:
return f(DC(
typename D::Dsi, a), b);
413 case it_uint:
return f(DC(
typename D::Dui, a), b);
415 case it_slong:
return f(DC(
typename D::Dsl, a), b);
416 case it_ulong:
return f(DC(
typename D::Dul, a), b);
418 case it_float:
return f(DC(
typename D::Dfloat,a), b);
419 case it_double:
return f(DC(
typename D::Ddouble,a), b);
421 assert(!
"unsupported pixel type in image");
422 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
440 template <
typename F,
typename A,
typename B>
441 static typename F::result_type
filter(
const F& f,
const A& a,
const B& b)
443 typedef typename Binder<B>::Derived D;
444 switch (b.get_pixel_type()) {
445 case it_bit:
return _filter(f, a, DC(
typename D::Dbool, b));
446 case it_sbyte:
return _filter(f, a, DC(
typename D::Dsc, b));
447 case it_ubyte:
return _filter(f, a, DC(
typename D::Duc, b));
448 case it_sshort:
return _filter(f, a, DC(
typename D::Dss, b));
449 case it_ushort:
return _filter(f, a, DC(
typename D::Dus, b));
450 case it_sint:
return _filter(f, a, DC(
typename D::Dsi, b));
451 case it_uint:
return _filter(f, a, DC(
typename D::Dui, b));
453 case it_slong:
return _filter(f, a, DC(
typename D::Dsl, b));
454 case it_ulong:
return _filter(f, a, DC(
typename D::Dul, b));
456 case it_float:
return _filter(f, a, DC(
typename D::Dfloat, b));
457 case it_double:
return _filter(f, a, DC(
typename D::Ddouble,b));
459 assert(!
"unsupported pixel type in image");
460 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
466 template <
typename F,
typename A,
typename B>
467 static typename F::result_type _accumulate(F& f,
const A& a,
const B& b)
469 typedef typename Binder<A>::Derived D;
470 switch (a.get_pixel_type()) {
471 case it_bit:
return f(DC(
typename D::Dbool, a), b);
472 case it_sbyte:
return f(DC(
typename D::Dsc, a), b);
473 case it_ubyte:
return f(DC(
typename D::Duc, a), b);
474 case it_sshort:
return f(DC(
typename D::Dss, a), b);
475 case it_ushort:
return f(DC(
typename D::Dus, a), b);
476 case it_sint:
return f(DC(
typename D::Dsi, a), b);
477 case it_uint:
return f(DC(
typename D::Dui, a), b);
479 case it_slong:
return f(DC(
typename D::Dsl, a), b);
480 case it_ulong:
return f(DC(
typename D::Dul, a), b);
482 case it_float:
return f(DC(
typename D::Dfloat,a), b);
483 case it_double:
return f(DC(
typename D::Ddouble,a), b);
485 assert(!
"unsupported pixel type in image");
486 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
503 template <
typename F,
typename A,
typename B>
504 static typename F::result_type
accumulate(F& f,
const A& a,
const B& b)
506 typedef typename Binder<B>::Derived D;
507 switch (b.get_pixel_type()) {
508 case it_bit:
return _accumulate(f, a, DC(
typename D::Dbool, b));
509 case it_sbyte:
return _accumulate(f, a, DC(
typename D::Dsc, b));
510 case it_ubyte:
return _accumulate(f, a, DC(
typename D::Duc, b));
511 case it_sshort:
return _accumulate(f, a, DC(
typename D::Dss, b));
512 case it_ushort:
return _accumulate(f, a, DC(
typename D::Dus, b));
513 case it_sint:
return _accumulate(f, a, DC(
typename D::Dsi, b));
514 case it_uint:
return _accumulate(f, a, DC(
typename D::Dui, b));
516 case it_slong:
return _accumulate(f, a, DC(
typename D::Dsl, b));
517 case it_ulong:
return _accumulate(f, a, DC(
typename D::Dul, b));
519 case it_float:
return _accumulate(f, a, DC(
typename D::Dfloat, b));
520 case it_double:
return _accumulate(f, a, DC(
typename D::Ddouble,b));
522 assert(!
"unsupported pixel type in image");
523 throw std::invalid_argument(
"mia::accumulate: unsupported pixel type in image");
541 return do_filter(image);
548 return do_filter(pimage);
555 return do_filter(*pimage);
result_type filter(const Image &image) const
D plugin_data
plugin handler helper type
static F::result_type filter_and_output(const F &f, const B &a, O &b)
base class for all filer type functors.
TFactory< TDataFilter< Image > >::Product Product
static void filter_equal_inplace(const F &f, const B &a, B &b)
TDataFilterPlugin(char const *const name)
Constructor that sets the plug-in name.
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
std::shared_ptr< TDataFilter< D > > Pointer
pointer type of the data filtered by this filter
static F::result_type filter(const F &f, const B &b)
D Image
defines the image type handled by the image filter
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Generic image filter plugin base.
R result_type
defines the return type of the filter function
static F::result_type accumulate(F &f, const B &data)
TFilter< std::shared_ptr< D > >::result_type result_type
result type of this filter
filter_type plugin_type
plugin handler helper type
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
The base class for all plug-in created object.
Generic interface class to data filters.
static F::result_type filter_inplace(const F &f, B &b)
static F::result_type filter_equal(const F &f, const B &a, const B &b)
#define NS_MIA_END
conveniance define to end the mia namespace