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;
119 std::set<EPixelType> test_pixeltype_conversion(
const std::set<EPixelType>& in_types)
const;
121 virtual result_type do_filter(
const Image& image)
const = 0;
122 virtual result_type do_filter(std::shared_ptr<D> image)
const;
124 virtual std::set<EPixelType> do_test_pixeltype_conversion(
const std::set<EPixelType>& in_type)
const;
135 m_chain.push_back(f);
139 virtual result_type do_filter(
const D& image)
const {
140 assert(m_chain.size() > 0);
142 cvdebug() <<
"Run chained filter '" << m_chain[0]->get_init_string() <<
"'\n";
143 result_type result = m_chain[0]->filter(image);
144 for(
auto f = m_chain.begin() + 1; f != m_chain.end(); ++f) {
145 cvdebug() <<
"Run chained filter '" << (*f)->get_init_string() <<
"'\n";
146 result = (*f)->filter(*result);
151 std::set<EPixelType> do_test_pixeltype_conversion(
const std::set<EPixelType>& in_type)
const 153 std::set<EPixelType> result = in_type;
154 for(
auto f: m_chain) {
155 result = f->test_pixeltype_conversion(result);
160 std::vector<Pointer> m_chain;
175 template <
class Image>
185 template <
typename D>
187 static constexpr
bool value =
true;
197 template <
template <
class>
class D>
199 typedef D<bool> Dbool;
200 typedef D<signed char> Dsc;
201 typedef D<unsigned char> Duc;
202 typedef D<signed short> Dss;
203 typedef D<unsigned short> Dus;
204 typedef D<signed int> Dsi;
205 typedef D<unsigned int> Dui;
207 typedef D<signed long> Dsl;
208 typedef D<unsigned long> Dul;
210 typedef D<float> Dfloat;
211 typedef D<double> Ddouble;
225 template <
typename B>
249 template <
typename F,
typename B>
250 static typename F::result_type
filter(
const F& f,
const B& b)
252 typedef typename Binder<B>::Derived D;
253 switch (b.get_pixel_type()) {
254 case it_bit:
return f(DC(
typename D::Dbool,b));
255 case it_sbyte:
return f(DC(
typename D::Dsc,b));
256 case it_ubyte:
return f(DC(
typename D::Duc,b));
257 case it_sshort:
return f(DC(
typename D::Dss,b));
258 case it_ushort:
return f(DC(
typename D::Dus,b));
259 case it_sint:
return f(DC(
typename D::Dsi,b));
260 case it_uint:
return f(DC(
typename D::Dui,b));
262 case it_slong:
return f(DC(
typename D::Dsl,b));
263 case it_ulong:
return f(DC(
typename D::Dul,b));
265 case it_float:
return f(DC(
typename D::Dfloat,b));
266 case it_double:
return f(DC(
typename D::Ddouble,b));
268 assert(!
"unsupported pixel type in image");
269 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
285 template <
typename F,
typename B>
288 typedef typename Binder<B>::Derived D;
289 switch (b.get_pixel_type()) {
290 case it_bit:
return f(DV(
typename D::Dbool,b));
291 case it_sbyte:
return f(DV(
typename D::Dsc,b));
292 case it_ubyte:
return f(DV(
typename D::Duc,b));
293 case it_sshort:
return f(DV(
typename D::Dss,b));
294 case it_ushort:
return f(DV(
typename D::Dus,b));
295 case it_sint:
return f(DV(
typename D::Dsi,b));
296 case it_uint:
return f(DV(
typename D::Dui,b));
298 case it_slong:
return f(DV(
typename D::Dsl,b));
299 case it_ulong:
return f(DV(
typename D::Dul,b));
301 case it_float:
return f(DV(
typename D::Dfloat,b));
302 case it_double:
return f(DV(
typename D::Ddouble,b));
304 assert(!
"unsupported pixel type in image");
305 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
320 template <
typename F,
typename B>
321 static typename F::result_type
accumulate(F& f,
const B& data)
323 typedef typename Binder<B>::Derived D;
324 switch (data.get_pixel_type()) {
325 case it_bit:
return f(DC(
typename D::Dbool,data));
326 case it_sbyte:
return f(DC(
typename D::Dsc,data));
327 case it_ubyte:
return f(DC(
typename D::Duc,data));
328 case it_sshort:
return f(DC(
typename D::Dss,data));
329 case it_ushort:
return f(DC(
typename D::Dus,data));
330 case it_sint:
return f(DC(
typename D::Dsi,data));
331 case it_uint:
return f(DC(
typename D::Dui,data));
333 case it_slong:
return f(DC(
typename D::Dsl,data));
334 case it_ulong:
return f(DC(
typename D::Dul,data));
336 case it_float:
return f(DC(
typename D::Dfloat,data));
337 case it_double:
return f(DC(
typename D::Ddouble,data));
339 assert(!
"unsupported pixel type in image");
340 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
344 template <
typename F,
typename INOUT,
typename IN>
347 typedef typename Binder<IN>::Derived D;
348 switch (in.get_pixel_type()) {
349 case it_bit:
return f(inout, DC(
typename D::Dbool, in));
350 case it_sbyte:
return f(inout, DC(
typename D::Dsc, in));
351 case it_ubyte:
return f(inout, DC(
typename D::Duc, in));
352 case it_sshort:
return f(inout, DC(
typename D::Dss, in));
353 case it_ushort:
return f(inout, DC(
typename D::Dus, in));
354 case it_sint:
return f(inout, DC(
typename D::Dsi, in));
355 case it_uint:
return f(inout, DC(
typename D::Dui, in));
357 case it_slong:
return f(inout, DC(
typename D::Dsl, in));
358 case it_ulong:
return f(inout, DC(
typename D::Dul, in));
360 case it_float:
return f(inout, DC(
typename D::Dfloat, in));
361 case it_double:
return f(inout, DC(
typename D::Ddouble, in));
363 assert(!
"unsupported pixel type in image");
364 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
368 template <
typename F,
typename INOUT,
typename IN>
369 static typename F::result_type
combine_inplace(
const F& f, INOUT& inout,
const IN& in)
371 typedef typename Binder<INOUT
373 switch (inout.get_pixel_type()) {
388 assert(!
"unsupported pixel type in image");
389 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
408 template <
typename F,
typename B>
409 static typename F::result_type
filter_equal(
const F& f,
const B& a,
const B& b)
411 assert(a.get_pixel_type() == b.get_pixel_type());
412 typedef typename Binder<B>::Derived D;
413 switch (a.get_pixel_type()) {
414 case it_bit:
return f(DC(
typename D::Dbool, a), DC(
typename D::Dbool,b));
415 case it_sbyte:
return f( DC(
typename D::Dsc, a), DC(
typename D::Dsc,b));
416 case it_ubyte:
return f( DC(
typename D::Duc, a), DC(
typename D::Duc,b));
417 case it_sshort:
return f( DC(
typename D::Dss, a), DC(
typename D::Dss,b));
418 case it_ushort:
return f( DC(
typename D::Dus, a), DC(
typename D::Dus,b));
419 case it_sint:
return f( DC(
typename D::Dsi, a), DC(
typename D::Dsi,b));
420 case it_uint:
return f( DC(
typename D::Dui, a), DC(
typename D::Dui,b));
422 case it_slong:
return f( DC(
typename D::Dsl, a), DC(
typename D::Dsl,b));
423 case it_ulong:
return f( DC(
typename D::Dul, a), DC(
typename D::Dul,b));
425 case it_float:
return f( DC(
typename D::Dfloat, a), DC(
typename D::Dfloat,b));
426 case it_double:
return f( DC(
typename D::Ddouble, a), DC(
typename D::Ddouble,b));
428 assert(!
"unsupported pixel type in image");
429 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
445 template <
typename F,
typename B>
448 assert(a.get_pixel_type() == b.get_pixel_type());
449 typedef typename Binder<B>::Derived D;
450 switch (a.get_pixel_type()) {
451 case it_bit: f(DC(
typename D::Dbool, a), DV(
typename D::Dbool,b));
break;
452 case it_sbyte: f( DC(
typename D::Dsc, a), DV(
typename D::Dsc,b));
break;
453 case it_ubyte: f( DC(
typename D::Duc, a), DV(
typename D::Duc,b));
break;
454 case it_sshort: f( DC(
typename D::Dss, a), DV(
typename D::Dss,b));
break;
455 case it_ushort: f( DC(
typename D::Dus, a), DV(
typename D::Dus,b));
break;
456 case it_sint: f( DC(
typename D::Dsi, a), DV(
typename D::Dsi,b));
break;
457 case it_uint: f( DC(
typename D::Dui, a), DV(
typename D::Dui,b));
break;
459 case it_slong: f( DC(
typename D::Dsl, a), DV(
typename D::Dsl,b));
break;
460 case it_ulong: f( DC(
typename D::Dul, a), DV(
typename D::Dul,b));
break;
462 case it_float: f( DC(
typename D::Dfloat, a), DV(
typename D::Dfloat,b));
break;
463 case it_double: f( DC(
typename D::Ddouble, a), DV(
typename D::Ddouble,b));
break;
465 assert(!
"unsupported pixel type in image");
466 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
482 template <
typename F,
typename B,
typename O>
485 typedef typename Binder<B>::Derived D;
486 switch (a.get_pixel_type()) {
487 case it_bit:
return f(DC(
typename D::Dbool, a), b);
break;
488 case it_sbyte:
return f(DC(
typename D::Dsc, a), b);
break;
489 case it_ubyte:
return f(DC(
typename D::Duc, a), b);
break;
490 case it_sshort:
return f(DC(
typename D::Dss, a), b);
break;
491 case it_ushort:
return f(DC(
typename D::Dus, a), b);
break;
492 case it_sint:
return f(DC(
typename D::Dsi, a), b);
break;
493 case it_uint:
return f(DC(
typename D::Dui, a), b);
break;
495 case it_slong:
return f(DC(
typename D::Dsl, a), b);
break;
496 case it_ulong:
return f(DC(
typename D::Dul, a), b);
break;
498 case it_float:
return f(DC(
typename D::Dfloat, a), b);
break;
499 case it_double:
return f(DC(
typename D::Ddouble, a), b);
break;
501 assert(!
"unsupported pixel type in image");
502 throw std::invalid_argument(
"mia::filter_and_output: unsupported pixel type in image");
508 template <
typename F,
typename A,
typename B>
509 static typename F::result_type _filter(
const F& f,
const A& a,
const B& b)
511 typedef typename Binder<A>::Derived D;
512 switch (a.get_pixel_type()) {
513 case it_bit:
return f(DC(
typename D::Dbool, a), b);
514 case it_sbyte:
return f(DC(
typename D::Dsc, a), b);
515 case it_ubyte:
return f(DC(
typename D::Duc, a), b);
516 case it_sshort:
return f(DC(
typename D::Dss, a), b);
517 case it_ushort:
return f(DC(
typename D::Dus, a), b);
518 case it_sint:
return f(DC(
typename D::Dsi, a), b);
519 case it_uint:
return f(DC(
typename D::Dui, a), b);
521 case it_slong:
return f(DC(
typename D::Dsl, a), b);
522 case it_ulong:
return f(DC(
typename D::Dul, a), b);
524 case it_float:
return f(DC(
typename D::Dfloat,a), b);
525 case it_double:
return f(DC(
typename D::Ddouble,a), b);
527 assert(!
"unsupported pixel type in image");
528 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
546 template <
typename F,
typename A,
typename B>
547 static typename F::result_type
filter(
const F& f,
const A& a,
const B& b)
549 typedef typename Binder<B>::Derived D;
550 switch (b.get_pixel_type()) {
551 case it_bit:
return _filter(f, a, DC(
typename D::Dbool, b));
552 case it_sbyte:
return _filter(f, a, DC(
typename D::Dsc, b));
553 case it_ubyte:
return _filter(f, a, DC(
typename D::Duc, b));
554 case it_sshort:
return _filter(f, a, DC(
typename D::Dss, b));
555 case it_ushort:
return _filter(f, a, DC(
typename D::Dus, b));
556 case it_sint:
return _filter(f, a, DC(
typename D::Dsi, b));
557 case it_uint:
return _filter(f, a, DC(
typename D::Dui, b));
559 case it_slong:
return _filter(f, a, DC(
typename D::Dsl, b));
560 case it_ulong:
return _filter(f, a, DC(
typename D::Dul, b));
562 case it_float:
return _filter(f, a, DC(
typename D::Dfloat, b));
563 case it_double:
return _filter(f, a, DC(
typename D::Ddouble,b));
565 assert(!
"unsupported pixel type in image");
566 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
572 template <
typename F,
typename A,
typename B>
573 static typename F::result_type _accumulate(F& f,
const A& a,
const B& b)
575 typedef typename Binder<A>::Derived D;
576 switch (a.get_pixel_type()) {
577 case it_bit:
return f(DC(
typename D::Dbool, a), b);
578 case it_sbyte:
return f(DC(
typename D::Dsc, a), b);
579 case it_ubyte:
return f(DC(
typename D::Duc, a), b);
580 case it_sshort:
return f(DC(
typename D::Dss, a), b);
581 case it_ushort:
return f(DC(
typename D::Dus, a), b);
582 case it_sint:
return f(DC(
typename D::Dsi, a), b);
583 case it_uint:
return f(DC(
typename D::Dui, a), b);
585 case it_slong:
return f(DC(
typename D::Dsl, a), b);
586 case it_ulong:
return f(DC(
typename D::Dul, a), b);
588 case it_float:
return f(DC(
typename D::Dfloat,a), b);
589 case it_double:
return f(DC(
typename D::Ddouble,a), b);
591 assert(!
"unsupported pixel type in image");
592 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
609 template <
typename F,
typename A,
typename B>
610 static typename F::result_type
accumulate(F& f,
const A& a,
const B& b)
612 typedef typename Binder<B>::Derived D;
613 switch (b.get_pixel_type()) {
614 case it_bit:
return _accumulate(f, a, DC(
typename D::Dbool, b));
615 case it_sbyte:
return _accumulate(f, a, DC(
typename D::Dsc, b));
616 case it_ubyte:
return _accumulate(f, a, DC(
typename D::Duc, b));
617 case it_sshort:
return _accumulate(f, a, DC(
typename D::Dss, b));
618 case it_ushort:
return _accumulate(f, a, DC(
typename D::Dus, b));
619 case it_sint:
return _accumulate(f, a, DC(
typename D::Dsi, b));
620 case it_uint:
return _accumulate(f, a, DC(
typename D::Dui, b));
622 case it_slong:
return _accumulate(f, a, DC(
typename D::Dsl, b));
623 case it_ulong:
return _accumulate(f, a, DC(
typename D::Dul, b));
625 case it_float:
return _accumulate(f, a, DC(
typename D::Dfloat, b));
626 case it_double:
return _accumulate(f, a, DC(
typename D::Ddouble,b));
628 assert(!
"unsupported pixel type in image");
629 throw std::invalid_argument(
"mia::accumulate: unsupported pixel type in image");
647 return do_filter(image);
654 return do_filter(pimage);
661 return do_filter(*pimage);
669 return do_test_pixeltype_conversion(in_types);
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
result_type filter(const Image &image) const
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
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
std::set< EPixelType > test_pixeltype_conversion(const std::set< EPixelType > &in_types) const
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