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;
114 virtual result_type do_filter(
const Image& image)
const = 0;
115 virtual result_type do_filter(std::shared_ptr<D> image)
const;
126 m_chain.push_back(f);
129 virtual result_type do_filter(
const D& image)
const {
130 assert(m_chain.size() > 0);
132 cvdebug() <<
"Run chained filter '" << m_chain[0]->get_init_string() <<
"'\n";
133 result_type result = m_chain[0]->filter(image);
134 for(
auto f = m_chain.begin() + 1; f != m_chain.end(); ++f) {
135 cvdebug() <<
"Run chained filter '" << (*f)->get_init_string() <<
"'\n";
136 result = (*f)->filter(*result);
140 std::vector<Pointer> m_chain;
155 template <
class Image>
165 template <
typename D>
177 template <
template <
class>
class D>
179 typedef D<bool> Dbool;
180 typedef D<signed char> Dsc;
181 typedef D<unsigned char> Duc;
182 typedef D<signed short> Dss;
183 typedef D<unsigned short> Dus;
184 typedef D<signed int> Dsi;
185 typedef D<unsigned int> Dui;
187 typedef D<signed long> Dsl;
188 typedef D<unsigned long> Dul;
190 typedef D<float> Dfloat;
191 typedef D<double> Ddouble;
205 template <
typename B>
229 template <
typename F,
typename B>
230 static typename F::result_type
filter(
const F& f,
const B& b)
232 typedef typename Binder<B>::Derived D;
233 switch (b.get_pixel_type()) {
234 case it_bit:
return f(DC(
typename D::Dbool,b));
235 case it_sbyte:
return f(DC(
typename D::Dsc,b));
236 case it_ubyte:
return f(DC(
typename D::Duc,b));
237 case it_sshort:
return f(DC(
typename D::Dss,b));
238 case it_ushort:
return f(DC(
typename D::Dus,b));
239 case it_sint:
return f(DC(
typename D::Dsi,b));
240 case it_uint:
return f(DC(
typename D::Dui,b));
242 case it_slong:
return f(DC(
typename D::Dsl,b));
243 case it_ulong:
return f(DC(
typename D::Dul,b));
245 case it_float:
return f(DC(
typename D::Dfloat,b));
246 case it_double:
return f(DC(
typename D::Ddouble,b));
248 assert(!
"unsupported pixel type in image");
249 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
265 template <
typename F,
typename B>
268 typedef typename Binder<B>::Derived D;
269 switch (b.get_pixel_type()) {
270 case it_bit:
return f(DV(
typename D::Dbool,b));
271 case it_sbyte:
return f(DV(
typename D::Dsc,b));
272 case it_ubyte:
return f(DV(
typename D::Duc,b));
273 case it_sshort:
return f(DV(
typename D::Dss,b));
274 case it_ushort:
return f(DV(
typename D::Dus,b));
275 case it_sint:
return f(DV(
typename D::Dsi,b));
276 case it_uint:
return f(DV(
typename D::Dui,b));
278 case it_slong:
return f(DV(
typename D::Dsl,b));
279 case it_ulong:
return f(DV(
typename D::Dul,b));
281 case it_float:
return f(DV(
typename D::Dfloat,b));
282 case it_double:
return f(DV(
typename D::Ddouble,b));
284 assert(!
"unsupported pixel type in image");
285 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
300 template <
typename F,
typename B>
301 static typename F::result_type
accumulate(F& f,
const B& data)
303 typedef typename Binder<B>::Derived D;
304 switch (data.get_pixel_type()) {
305 case it_bit:
return f(DC(
typename D::Dbool,data));
306 case it_sbyte:
return f(DC(
typename D::Dsc,data));
307 case it_ubyte:
return f(DC(
typename D::Duc,data));
308 case it_sshort:
return f(DC(
typename D::Dss,data));
309 case it_ushort:
return f(DC(
typename D::Dus,data));
310 case it_sint:
return f(DC(
typename D::Dsi,data));
311 case it_uint:
return f(DC(
typename D::Dui,data));
313 case it_slong:
return f(DC(
typename D::Dsl,data));
314 case it_ulong:
return f(DC(
typename D::Dul,data));
316 case it_float:
return f(DC(
typename D::Dfloat,data));
317 case it_double:
return f(DC(
typename D::Ddouble,data));
319 assert(!
"unsupported pixel type in image");
320 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
324 template <
typename F,
typename INOUT,
typename IN>
327 typedef typename Binder<IN>::Derived D;
328 switch (in.get_pixel_type()) {
329 case it_bit:
return f(inout, DC(
typename D::Dbool, in));
330 case it_sbyte:
return f(inout, DC(
typename D::Dsc, in));
331 case it_ubyte:
return f(inout, DC(
typename D::Duc, in));
332 case it_sshort:
return f(inout, DC(
typename D::Dss, in));
333 case it_ushort:
return f(inout, DC(
typename D::Dus, in));
334 case it_sint:
return f(inout, DC(
typename D::Dsi, in));
335 case it_uint:
return f(inout, DC(
typename D::Dui, in));
337 case it_slong:
return f(inout, DC(
typename D::Dsl, in));
338 case it_ulong:
return f(inout, DC(
typename D::Dul, in));
340 case it_float:
return f(inout, DC(
typename D::Dfloat, in));
341 case it_double:
return f(inout, DC(
typename D::Ddouble, in));
343 assert(!
"unsupported pixel type in image");
344 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
348 template <
typename F,
typename INOUT,
typename IN>
349 static typename F::result_type
combine_inplace(
const F& f, INOUT& inout,
const IN& in)
351 typedef typename Binder<INOUT
353 switch (inout.get_pixel_type()) {
368 assert(!
"unsupported pixel type in image");
369 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
388 template <
typename F,
typename B>
389 static typename F::result_type
filter_equal(
const F& f,
const B& a,
const B& b)
391 assert(a.get_pixel_type() == b.get_pixel_type());
392 typedef typename Binder<B>::Derived D;
393 switch (a.get_pixel_type()) {
394 case it_bit:
return f(DC(
typename D::Dbool, a), DC(
typename D::Dbool,b));
395 case it_sbyte:
return f( DC(
typename D::Dsc, a), DC(
typename D::Dsc,b));
396 case it_ubyte:
return f( DC(
typename D::Duc, a), DC(
typename D::Duc,b));
397 case it_sshort:
return f( DC(
typename D::Dss, a), DC(
typename D::Dss,b));
398 case it_ushort:
return f( DC(
typename D::Dus, a), DC(
typename D::Dus,b));
399 case it_sint:
return f( DC(
typename D::Dsi, a), DC(
typename D::Dsi,b));
400 case it_uint:
return f( DC(
typename D::Dui, a), DC(
typename D::Dui,b));
402 case it_slong:
return f( DC(
typename D::Dsl, a), DC(
typename D::Dsl,b));
403 case it_ulong:
return f( DC(
typename D::Dul, a), DC(
typename D::Dul,b));
405 case it_float:
return f( DC(
typename D::Dfloat, a), DC(
typename D::Dfloat,b));
406 case it_double:
return f( DC(
typename D::Ddouble, a), DC(
typename D::Ddouble,b));
408 assert(!
"unsupported pixel type in image");
409 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
425 template <
typename F,
typename B>
428 assert(a.get_pixel_type() == b.get_pixel_type());
429 typedef typename Binder<B>::Derived D;
430 switch (a.get_pixel_type()) {
431 case it_bit: f(DC(
typename D::Dbool, a), DV(
typename D::Dbool,b));
break;
432 case it_sbyte: f( DC(
typename D::Dsc, a), DV(
typename D::Dsc,b));
break;
433 case it_ubyte: f( DC(
typename D::Duc, a), DV(
typename D::Duc,b));
break;
434 case it_sshort: f( DC(
typename D::Dss, a), DV(
typename D::Dss,b));
break;
435 case it_ushort: f( DC(
typename D::Dus, a), DV(
typename D::Dus,b));
break;
436 case it_sint: f( DC(
typename D::Dsi, a), DV(
typename D::Dsi,b));
break;
437 case it_uint: f( DC(
typename D::Dui, a), DV(
typename D::Dui,b));
break;
439 case it_slong: f( DC(
typename D::Dsl, a), DV(
typename D::Dsl,b));
break;
440 case it_ulong: f( DC(
typename D::Dul, a), DV(
typename D::Dul,b));
break;
442 case it_float: f( DC(
typename D::Dfloat, a), DV(
typename D::Dfloat,b));
break;
443 case it_double: f( DC(
typename D::Ddouble, a), DV(
typename D::Ddouble,b));
break;
445 assert(!
"unsupported pixel type in image");
446 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
462 template <
typename F,
typename B,
typename O>
465 typedef typename Binder<B>::Derived D;
466 switch (a.get_pixel_type()) {
467 case it_bit:
return f(DC(
typename D::Dbool, a), b);
break;
468 case it_sbyte:
return f(DC(
typename D::Dsc, a), b);
break;
469 case it_ubyte:
return f(DC(
typename D::Duc, a), b);
break;
470 case it_sshort:
return f(DC(
typename D::Dss, a), b);
break;
471 case it_ushort:
return f(DC(
typename D::Dus, a), b);
break;
472 case it_sint:
return f(DC(
typename D::Dsi, a), b);
break;
473 case it_uint:
return f(DC(
typename D::Dui, a), b);
break;
475 case it_slong:
return f(DC(
typename D::Dsl, a), b);
break;
476 case it_ulong:
return f(DC(
typename D::Dul, a), b);
break;
478 case it_float:
return f(DC(
typename D::Dfloat, a), b);
break;
479 case it_double:
return f(DC(
typename D::Ddouble, a), b);
break;
481 assert(!
"unsupported pixel type in image");
482 throw std::invalid_argument(
"mia::filter_and_output: unsupported pixel type in image");
488 template <
typename F,
typename A,
typename B>
489 static typename F::result_type _filter(
const F& f,
const A& a,
const B& b)
491 typedef typename Binder<A>::Derived D;
492 switch (a.get_pixel_type()) {
493 case it_bit:
return f(DC(
typename D::Dbool, a), b);
494 case it_sbyte:
return f(DC(
typename D::Dsc, a), b);
495 case it_ubyte:
return f(DC(
typename D::Duc, a), b);
496 case it_sshort:
return f(DC(
typename D::Dss, a), b);
497 case it_ushort:
return f(DC(
typename D::Dus, a), b);
498 case it_sint:
return f(DC(
typename D::Dsi, a), b);
499 case it_uint:
return f(DC(
typename D::Dui, a), b);
501 case it_slong:
return f(DC(
typename D::Dsl, a), b);
502 case it_ulong:
return f(DC(
typename D::Dul, a), b);
504 case it_float:
return f(DC(
typename D::Dfloat,a), b);
505 case it_double:
return f(DC(
typename D::Ddouble,a), b);
507 assert(!
"unsupported pixel type in image");
508 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
526 template <
typename F,
typename A,
typename B>
527 static typename F::result_type
filter(
const F& f,
const A& a,
const B& b)
529 typedef typename Binder<B>::Derived D;
530 switch (b.get_pixel_type()) {
531 case it_bit:
return _filter(f, a, DC(
typename D::Dbool, b));
532 case it_sbyte:
return _filter(f, a, DC(
typename D::Dsc, b));
533 case it_ubyte:
return _filter(f, a, DC(
typename D::Duc, b));
534 case it_sshort:
return _filter(f, a, DC(
typename D::Dss, b));
535 case it_ushort:
return _filter(f, a, DC(
typename D::Dus, b));
536 case it_sint:
return _filter(f, a, DC(
typename D::Dsi, b));
537 case it_uint:
return _filter(f, a, DC(
typename D::Dui, b));
539 case it_slong:
return _filter(f, a, DC(
typename D::Dsl, b));
540 case it_ulong:
return _filter(f, a, DC(
typename D::Dul, b));
542 case it_float:
return _filter(f, a, DC(
typename D::Dfloat, b));
543 case it_double:
return _filter(f, a, DC(
typename D::Ddouble,b));
545 assert(!
"unsupported pixel type in image");
546 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
552 template <
typename F,
typename A,
typename B>
553 static typename F::result_type _accumulate(F& f,
const A& a,
const B& b)
555 typedef typename Binder<A>::Derived D;
556 switch (a.get_pixel_type()) {
557 case it_bit:
return f(DC(
typename D::Dbool, a), b);
558 case it_sbyte:
return f(DC(
typename D::Dsc, a), b);
559 case it_ubyte:
return f(DC(
typename D::Duc, a), b);
560 case it_sshort:
return f(DC(
typename D::Dss, a), b);
561 case it_ushort:
return f(DC(
typename D::Dus, a), b);
562 case it_sint:
return f(DC(
typename D::Dsi, a), b);
563 case it_uint:
return f(DC(
typename D::Dui, a), b);
565 case it_slong:
return f(DC(
typename D::Dsl, a), b);
566 case it_ulong:
return f(DC(
typename D::Dul, a), b);
568 case it_float:
return f(DC(
typename D::Dfloat,a), b);
569 case it_double:
return f(DC(
typename D::Ddouble,a), b);
571 assert(!
"unsupported pixel type in image");
572 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
589 template <
typename F,
typename A,
typename B>
590 static typename F::result_type
accumulate(F& f,
const A& a,
const B& b)
592 typedef typename Binder<B>::Derived D;
593 switch (b.get_pixel_type()) {
594 case it_bit:
return _accumulate(f, a, DC(
typename D::Dbool, b));
595 case it_sbyte:
return _accumulate(f, a, DC(
typename D::Dsc, b));
596 case it_ubyte:
return _accumulate(f, a, DC(
typename D::Duc, b));
597 case it_sshort:
return _accumulate(f, a, DC(
typename D::Dss, b));
598 case it_ushort:
return _accumulate(f, a, DC(
typename D::Dus, b));
599 case it_sint:
return _accumulate(f, a, DC(
typename D::Dsi, b));
600 case it_uint:
return _accumulate(f, a, DC(
typename D::Dui, b));
602 case it_slong:
return _accumulate(f, a, DC(
typename D::Dsl, b));
603 case it_ulong:
return _accumulate(f, a, DC(
typename D::Dul, b));
605 case it_float:
return _accumulate(f, a, DC(
typename D::Dfloat, b));
606 case it_double:
return _accumulate(f, a, DC(
typename D::Ddouble,b));
608 assert(!
"unsupported pixel type in image");
609 throw std::invalid_argument(
"mia::accumulate: unsupported pixel type in image");
627 return do_filter(image);
634 return do_filter(pimage);
641 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)
static F::result_type combine_inplace(const F &f, INOUT &inout, const IN &in)
static F::result_type _combine_inplace(const F &f, INOUT &inout, const IN &in)
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
static constexpr bool value
void push_back(Pointer f)
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)
TDataFilterChained< D > Chained
TDataFilter< D >::Pointer Pointer
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