21 #ifndef mia_core_filter_hh 22 #define mia_core_filter_hh 39 static const char *type_descr;
46 static const char *type_descr;
49 #define DC(T, D) dynamic_cast<const T&>(D) 50 #define DV(T, D) dynamic_cast<T&>(D) 98 typedef std::shared_ptr<TDataFilter<D> >
Pointer;
108 result_type
filter(
const Image& image)
const;
113 result_type
filter(std::shared_ptr<D> pimage)
const;
121 std::set<EPixelType> test_pixeltype_conversion(
const std::set<EPixelType>& in_types)
const;
123 virtual result_type do_filter(
const Image& image)
const = 0;
124 virtual result_type do_filter(std::shared_ptr<D> image)
const;
126 virtual std::set<EPixelType> do_test_pixeltype_conversion(
const std::set<EPixelType>& in_type)
const;
137 m_chain.push_back(f);
141 virtual result_type do_filter(
const D& image)
const {
142 assert(m_chain.size() > 0);
144 cvdebug() <<
"Run chained filter '" << m_chain[0]->get_init_string() <<
"'\n";
145 result_type result = m_chain[0]->filter(image);
146 for(
auto f = m_chain.begin() + 1; f != m_chain.end(); ++f) {
147 cvdebug() <<
"Run chained filter '" << (*f)->get_init_string() <<
"'\n";
148 result = (*f)->filter(*result);
153 std::set<EPixelType> do_test_pixeltype_conversion(
const std::set<EPixelType>& in_type)
const 155 std::set<EPixelType> result = in_type;
156 for(
auto f: m_chain) {
157 result = f->test_pixeltype_conversion(result);
162 std::vector<Pointer> m_chain;
177 template <
class Image>
187 template <
typename D>
189 static constexpr
bool value =
true;
199 template <
template <
class>
class D>
201 typedef D<bool> Dbool;
202 typedef D<int8_t> Dsc;
203 typedef D<uint8_t> Duc;
204 typedef D<int16_t> Dss;
205 typedef D<uint16_t> Dus;
206 typedef D<int32_t> Dsi;
207 typedef D<uint32_t> Dui;
208 typedef D<int64_t> Dsl;
209 typedef D<uint64_t> 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));
261 case it_slong:
return f(DC(
typename D::Dsl,b));
262 case it_ulong:
return f(DC(
typename D::Dul,b));
263 case it_float:
return f(DC(
typename D::Dfloat,b));
264 case it_double:
return f(DC(
typename D::Ddouble,b));
266 assert(!
"unsupported pixel type in image");
267 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
283 template <
typename F,
typename B>
286 typedef typename Binder<B>::Derived D;
287 switch (b.get_pixel_type()) {
288 case it_bit:
return f(DV(
typename D::Dbool,b));
289 case it_sbyte:
return f(DV(
typename D::Dsc,b));
290 case it_ubyte:
return f(DV(
typename D::Duc,b));
291 case it_sshort:
return f(DV(
typename D::Dss,b));
292 case it_ushort:
return f(DV(
typename D::Dus,b));
293 case it_sint:
return f(DV(
typename D::Dsi,b));
294 case it_uint:
return f(DV(
typename D::Dui,b));
295 case it_slong:
return f(DV(
typename D::Dsl,b));
296 case it_ulong:
return f(DV(
typename D::Dul,b));
297 case it_float:
return f(DV(
typename D::Dfloat,b));
298 case it_double:
return f(DV(
typename D::Ddouble,b));
300 assert(!
"unsupported pixel type in image");
301 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
316 template <
typename F,
typename B>
317 static typename F::result_type
accumulate(F& f,
const B& data)
319 typedef typename Binder<B>::Derived D;
320 switch (data.get_pixel_type()) {
321 case it_bit:
return f(DC(
typename D::Dbool,data));
322 case it_sbyte:
return f(DC(
typename D::Dsc,data));
323 case it_ubyte:
return f(DC(
typename D::Duc,data));
324 case it_sshort:
return f(DC(
typename D::Dss,data));
325 case it_ushort:
return f(DC(
typename D::Dus,data));
326 case it_sint:
return f(DC(
typename D::Dsi,data));
327 case it_uint:
return f(DC(
typename D::Dui,data));
328 case it_slong:
return f(DC(
typename D::Dsl,data));
329 case it_ulong:
return f(DC(
typename D::Dul,data));
330 case it_float:
return f(DC(
typename D::Dfloat,data));
331 case it_double:
return f(DC(
typename D::Ddouble,data));
333 assert(!
"unsupported pixel type in image");
334 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
338 template <
typename F,
typename INOUT,
typename IN>
341 typedef typename Binder<IN>::Derived D;
342 switch (in.get_pixel_type()) {
343 case it_bit:
return f(inout, DC(
typename D::Dbool, in));
344 case it_sbyte:
return f(inout, DC(
typename D::Dsc, in));
345 case it_ubyte:
return f(inout, DC(
typename D::Duc, in));
346 case it_sshort:
return f(inout, DC(
typename D::Dss, in));
347 case it_ushort:
return f(inout, DC(
typename D::Dus, in));
348 case it_sint:
return f(inout, DC(
typename D::Dsi, in));
349 case it_uint:
return f(inout, DC(
typename D::Dui, in));
350 case it_slong:
return f(inout, DC(
typename D::Dsl, in));
351 case it_ulong:
return f(inout, DC(
typename D::Dul, in));
352 case it_float:
return f(inout, DC(
typename D::Dfloat, in));
353 case it_double:
return f(inout, DC(
typename D::Ddouble, in));
355 assert(!
"unsupported pixel type in image");
356 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
360 template <
typename F,
typename INOUT,
typename IN>
361 static typename F::result_type
combine_inplace(
const F& f, INOUT& inout,
const IN& in)
363 typedef typename Binder<INOUT
365 switch (inout.get_pixel_type()) {
378 assert(!
"unsupported pixel type in image");
379 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
398 template <
typename F,
typename B>
399 static typename F::result_type
filter_equal(
const F& f,
const B& a,
const B& b)
401 assert(a.get_pixel_type() == b.get_pixel_type());
402 typedef typename Binder<B>::Derived D;
403 switch (a.get_pixel_type()) {
404 case it_bit:
return f(DC(
typename D::Dbool, a), DC(
typename D::Dbool,b));
405 case it_sbyte:
return f( DC(
typename D::Dsc, a), DC(
typename D::Dsc,b));
406 case it_ubyte:
return f( DC(
typename D::Duc, a), DC(
typename D::Duc,b));
407 case it_sshort:
return f( DC(
typename D::Dss, a), DC(
typename D::Dss,b));
408 case it_ushort:
return f( DC(
typename D::Dus, a), DC(
typename D::Dus,b));
409 case it_sint:
return f( DC(
typename D::Dsi, a), DC(
typename D::Dsi,b));
410 case it_uint:
return f( DC(
typename D::Dui, a), DC(
typename D::Dui,b));
411 case it_slong:
return f( DC(
typename D::Dsl, a), DC(
typename D::Dsl,b));
412 case it_ulong:
return f( DC(
typename D::Dul, a), DC(
typename D::Dul,b));
413 case it_float:
return f( DC(
typename D::Dfloat, a), DC(
typename D::Dfloat,b));
414 case it_double:
return f( DC(
typename D::Ddouble, a), DC(
typename D::Ddouble,b));
416 assert(!
"unsupported pixel type in image");
417 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
433 template <
typename F,
typename B>
436 assert(a.get_pixel_type() == b.get_pixel_type());
437 typedef typename Binder<B>::Derived D;
438 switch (a.get_pixel_type()) {
439 case it_bit: f(DC(
typename D::Dbool, a), DV(
typename D::Dbool,b));
break;
440 case it_sbyte: f( DC(
typename D::Dsc, a), DV(
typename D::Dsc,b));
break;
441 case it_ubyte: f( DC(
typename D::Duc, a), DV(
typename D::Duc,b));
break;
442 case it_sshort: f( DC(
typename D::Dss, a), DV(
typename D::Dss,b));
break;
443 case it_ushort: f( DC(
typename D::Dus, a), DV(
typename D::Dus,b));
break;
444 case it_sint: f( DC(
typename D::Dsi, a), DV(
typename D::Dsi,b));
break;
445 case it_uint: f( DC(
typename D::Dui, a), DV(
typename D::Dui,b));
break;
446 case it_slong: f( DC(
typename D::Dsl, a), DV(
typename D::Dsl,b));
break;
447 case it_ulong: f( DC(
typename D::Dul, a), DV(
typename D::Dul,b));
break;
448 case it_float: f( DC(
typename D::Dfloat, a), DV(
typename D::Dfloat,b));
break;
449 case it_double: f( DC(
typename D::Ddouble, a), DV(
typename D::Ddouble,b));
break;
451 assert(!
"unsupported pixel type in image");
452 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
468 template <
typename F,
typename B,
typename O>
471 typedef typename Binder<B>::Derived D;
472 switch (a.get_pixel_type()) {
473 case it_bit:
return f(DC(
typename D::Dbool, a), b);
break;
474 case it_sbyte:
return f(DC(
typename D::Dsc, a), b);
break;
475 case it_ubyte:
return f(DC(
typename D::Duc, a), b);
break;
476 case it_sshort:
return f(DC(
typename D::Dss, a), b);
break;
477 case it_ushort:
return f(DC(
typename D::Dus, a), b);
break;
478 case it_sint:
return f(DC(
typename D::Dsi, a), b);
break;
479 case it_uint:
return f(DC(
typename D::Dui, a), b);
break;
480 case it_slong:
return f(DC(
typename D::Dsl, a), b);
break;
481 case it_ulong:
return f(DC(
typename D::Dul, a), b);
break;
482 case it_float:
return f(DC(
typename D::Dfloat, a), b);
break;
483 case it_double:
return f(DC(
typename D::Ddouble, a), b);
break;
485 assert(!
"unsupported pixel type in image");
486 throw std::invalid_argument(
"mia::filter_and_output: unsupported pixel type in image");
492 template <
typename F,
typename A,
typename B>
493 static typename F::result_type _filter(
const F& f,
const A& a,
const B& b)
495 typedef typename Binder<A>::Derived D;
496 switch (a.get_pixel_type()) {
497 case it_bit:
return f(DC(
typename D::Dbool, a), b);
498 case it_sbyte:
return f(DC(
typename D::Dsc, a), b);
499 case it_ubyte:
return f(DC(
typename D::Duc, a), b);
500 case it_sshort:
return f(DC(
typename D::Dss, a), b);
501 case it_ushort:
return f(DC(
typename D::Dus, a), b);
502 case it_sint:
return f(DC(
typename D::Dsi, a), b);
503 case it_uint:
return f(DC(
typename D::Dui, a), b);
504 case it_slong:
return f(DC(
typename D::Dsl, a), b);
505 case it_ulong:
return f(DC(
typename D::Dul, a), b);
506 case it_float:
return f(DC(
typename D::Dfloat,a), b);
507 case it_double:
return f(DC(
typename D::Ddouble,a), b);
509 assert(!
"unsupported pixel type in image");
510 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
528 template <
typename F,
typename A,
typename B>
529 static typename F::result_type
filter(
const F& f,
const A& a,
const B& b)
531 typedef typename Binder<B>::Derived D;
532 switch (b.get_pixel_type()) {
533 case it_bit:
return _filter(f, a, DC(
typename D::Dbool, b));
534 case it_sbyte:
return _filter(f, a, DC(
typename D::Dsc, b));
535 case it_ubyte:
return _filter(f, a, DC(
typename D::Duc, b));
536 case it_sshort:
return _filter(f, a, DC(
typename D::Dss, b));
537 case it_ushort:
return _filter(f, a, DC(
typename D::Dus, b));
538 case it_sint:
return _filter(f, a, DC(
typename D::Dsi, b));
539 case it_uint:
return _filter(f, a, DC(
typename D::Dui, b));
540 case it_slong:
return _filter(f, a, DC(
typename D::Dsl, b));
541 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);
564 case it_slong:
return f(DC(
typename D::Dsl, a), b);
565 case it_ulong:
return f(DC(
typename D::Dul, a), b);
566 case it_float:
return f(DC(
typename D::Dfloat,a), b);
567 case it_double:
return f(DC(
typename D::Ddouble,a), b);
569 assert(!
"unsupported pixel type in image");
570 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
587 template <
typename F,
typename A,
typename B>
588 static typename F::result_type
accumulate(F& f,
const A& a,
const B& b)
590 typedef typename Binder<B>::Derived D;
591 switch (b.get_pixel_type()) {
592 case it_bit:
return _accumulate(f, a, DC(
typename D::Dbool, b));
593 case it_sbyte:
return _accumulate(f, a, DC(
typename D::Dsc, b));
594 case it_ubyte:
return _accumulate(f, a, DC(
typename D::Duc, b));
595 case it_sshort:
return _accumulate(f, a, DC(
typename D::Dss, b));
596 case it_ushort:
return _accumulate(f, a, DC(
typename D::Dus, b));
597 case it_sint:
return _accumulate(f, a, DC(
typename D::Dsi, b));
598 case it_uint:
return _accumulate(f, a, DC(
typename D::Dui, b));
599 case it_slong:
return _accumulate(f, a, DC(
typename D::Dsl, b));
600 case it_ulong:
return _accumulate(f, a, DC(
typename D::Dul, b));
601 case it_float:
return _accumulate(f, a, DC(
typename D::Dfloat, b));
602 case it_double:
return _accumulate(f, a, DC(
typename D::Ddouble,b));
604 assert(!
"unsupported pixel type in image");
605 throw std::invalid_argument(
"mia::accumulate: unsupported pixel type in image");
623 return do_filter(image);
630 return do_filter(pimage);
637 return do_filter(*pimage);
645 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