Go to the documentation of this file.
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)
99 typedef std::shared_ptr<TDataFilter<D>>
Pointer;
125 virtual result_type do_filter(std::shared_ptr<D> image)
const;
127 virtual std::set<EPixelType> do_test_pixeltype_conversion(
const std::set<EPixelType>& in_type)
const;
140 m_chain.push_back(f);
144 virtual result_type do_filter(
const D& image)
const
146 assert(m_chain.size() > 0);
147 cvdebug() <<
"Run chained filter '" << m_chain[0]->get_init_string() <<
"'\n";
148 result_type result = m_chain[0]->filter(image);
150 for (
auto f = m_chain.begin() + 1; f != m_chain.end(); ++f) {
151 cvdebug() <<
"Run chained filter '" << (*f)->get_init_string() <<
"'\n";
152 result = (*f)->filter(*result);
158 std::set<EPixelType> do_test_pixeltype_conversion(
const std::set<EPixelType>& in_type)
const
160 std::set<EPixelType> result = in_type;
162 for (
auto f : m_chain) {
163 result = f->test_pixeltype_conversion(result);
169 std::vector<Pointer> m_chain;
184 template <
class Image>
195 template <
typename D>
207 template <
template <
class>
class D>
209 typedef D<bool> Dbool;
210 typedef D<int8_t> Dsc;
211 typedef D<uint8_t> Duc;
212 typedef D<int16_t> Dss;
213 typedef D<uint16_t> Dus;
214 typedef D<int32_t> Dsi;
215 typedef D<uint32_t> Dui;
216 typedef D<int64_t> Dsl;
217 typedef D<uint64_t> Dul;
218 typedef D<float> Dfloat;
219 typedef D<double> Ddouble;
233 template <
typename B>
257 template <
typename F,
typename B>
258 static typename F::result_type
filter(
const F& f,
const B& b)
260 typedef typename Binder<B>::Derived D;
262 switch (b.get_pixel_type()) {
264 return f(DC(
typename D::Dbool, b));
267 return f(DC(
typename D::Dsc, b));
270 return f(DC(
typename D::Duc, b));
273 return f(DC(
typename D::Dss, b));
276 return f(DC(
typename D::Dus, b));
279 return f(DC(
typename D::Dsi, b));
282 return f(DC(
typename D::Dui, b));
285 return f(DC(
typename D::Dsl, b));
288 return f(DC(
typename D::Dul, b));
291 return f(DC(
typename D::Dfloat, b));
294 return f(DC(
typename D::Ddouble, b));
297 assert(!
"unsupported pixel type in image");
298 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
314 template <
typename F,
typename B>
317 typedef typename Binder<B>::Derived D;
319 switch (b.get_pixel_type()) {
321 return f(DV(
typename D::Dbool, b));
324 return f(DV(
typename D::Dsc, b));
327 return f(DV(
typename D::Duc, b));
330 return f(DV(
typename D::Dss, b));
333 return f(DV(
typename D::Dus, b));
336 return f(DV(
typename D::Dsi, b));
339 return f(DV(
typename D::Dui, b));
342 return f(DV(
typename D::Dsl, b));
345 return f(DV(
typename D::Dul, b));
348 return f(DV(
typename D::Dfloat, b));
351 return f(DV(
typename D::Ddouble, b));
354 assert(!
"unsupported pixel type in image");
355 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
370 template <
typename F,
typename B>
371 static typename F::result_type
accumulate(F& f,
const B& data)
373 typedef typename Binder<B>::Derived D;
375 switch (data.get_pixel_type()) {
377 return f(DC(
typename D::Dbool, data));
380 return f(DC(
typename D::Dsc, data));
383 return f(DC(
typename D::Duc, data));
386 return f(DC(
typename D::Dss, data));
389 return f(DC(
typename D::Dus, data));
392 return f(DC(
typename D::Dsi, data));
395 return f(DC(
typename D::Dui, data));
398 return f(DC(
typename D::Dsl, data));
401 return f(DC(
typename D::Dul, data));
404 return f(DC(
typename D::Dfloat, data));
407 return f(DC(
typename D::Ddouble, data));
410 assert(!
"unsupported pixel type in image");
411 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
415 template <
typename F,
typename INOUT,
typename IN>
418 typedef typename Binder<IN>::Derived D;
420 switch (in.get_pixel_type()) {
422 return f(inout, DC(
typename D::Dbool, in));
425 return f(inout, DC(
typename D::Dsc, in));
428 return f(inout, DC(
typename D::Duc, in));
431 return f(inout, DC(
typename D::Dss, in));
434 return f(inout, DC(
typename D::Dus, in));
437 return f(inout, DC(
typename D::Dsi, in));
440 return f(inout, DC(
typename D::Dui, in));
443 return f(inout, DC(
typename D::Dsl, in));
446 return f(inout, DC(
typename D::Dul, in));
449 return f(inout, DC(
typename D::Dfloat, in));
452 return f(inout, DC(
typename D::Ddouble, in));
455 assert(!
"unsupported pixel type in image");
456 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
460 template <
typename F,
typename INOUT,
typename IN>
461 static typename F::result_type
combine_inplace(
const F& f, INOUT& inout,
const IN& in)
463 typedef typename Binder<INOUT
466 switch (inout.get_pixel_type()) {
501 assert(!
"unsupported pixel type in image");
502 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
519 template <
typename F,
typename B>
520 static typename F::result_type
filter_equal(
const F& f,
const B& a,
const B& b)
522 assert(a.get_pixel_type() == b.get_pixel_type());
523 typedef typename Binder<B>::Derived D;
525 switch (a.get_pixel_type()) {
527 return f(DC(
typename D::Dbool, a), DC(
typename D::Dbool, b));
530 return f( DC(
typename D::Dsc, a), DC(
typename D::Dsc, b));
533 return f( DC(
typename D::Duc, a), DC(
typename D::Duc, b));
536 return f( DC(
typename D::Dss, a), DC(
typename D::Dss, b));
539 return f( DC(
typename D::Dus, a), DC(
typename D::Dus, b));
542 return f( DC(
typename D::Dsi, a), DC(
typename D::Dsi, b));
545 return f( DC(
typename D::Dui, a), DC(
typename D::Dui, b));
548 return f( DC(
typename D::Dsl, a), DC(
typename D::Dsl, b));
551 return f( DC(
typename D::Dul, a), DC(
typename D::Dul, b));
554 return f( DC(
typename D::Dfloat, a), DC(
typename D::Dfloat, b));
557 return f( DC(
typename D::Ddouble, a), DC(
typename D::Ddouble, b));
560 assert(!
"unsupported pixel type in image");
561 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
577 template <
typename F,
typename B>
580 assert(a.get_pixel_type() == b.get_pixel_type());
581 typedef typename Binder<B>::Derived D;
583 switch (a.get_pixel_type()) {
585 f(DC(
typename D::Dbool, a), DV(
typename D::Dbool, b));
589 f( DC(
typename D::Dsc, a), DV(
typename D::Dsc, b));
593 f( DC(
typename D::Duc, a), DV(
typename D::Duc, b));
597 f( DC(
typename D::Dss, a), DV(
typename D::Dss, b));
601 f( DC(
typename D::Dus, a), DV(
typename D::Dus, b));
605 f( DC(
typename D::Dsi, a), DV(
typename D::Dsi, b));
609 f( DC(
typename D::Dui, a), DV(
typename D::Dui, b));
613 f( DC(
typename D::Dsl, a), DV(
typename D::Dsl, b));
617 f( DC(
typename D::Dul, a), DV(
typename D::Dul, b));
621 f( DC(
typename D::Dfloat, a), DV(
typename D::Dfloat, b));
625 f( DC(
typename D::Ddouble, a), DV(
typename D::Ddouble, b));
629 assert(!
"unsupported pixel type in image");
630 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
646 template <
typename F,
typename B,
typename O>
649 typedef typename Binder<B>::Derived D;
651 switch (a.get_pixel_type()) {
653 return f(DC(
typename D::Dbool, a), b);
657 return f(DC(
typename D::Dsc, a), b);
661 return f(DC(
typename D::Duc, a), b);
665 return f(DC(
typename D::Dss, a), b);
669 return f(DC(
typename D::Dus, a), b);
673 return f(DC(
typename D::Dsi, a), b);
677 return f(DC(
typename D::Dui, a), b);
681 return f(DC(
typename D::Dsl, a), b);
685 return f(DC(
typename D::Dul, a), b);
689 return f(DC(
typename D::Dfloat, a), b);
693 return f(DC(
typename D::Ddouble, a), b);
697 assert(!
"unsupported pixel type in image");
698 throw std::invalid_argument(
"mia::filter_and_output: unsupported pixel type in image");
704 template <
typename F,
typename A,
typename B>
705 static typename F::result_type _filter(
const F& f,
const A& a,
const B& b)
707 typedef typename Binder<A>::Derived D;
709 switch (a.get_pixel_type()) {
711 return f(DC(
typename D::Dbool, a), b);
714 return f(DC(
typename D::Dsc, a), b);
717 return f(DC(
typename D::Duc, a), b);
720 return f(DC(
typename D::Dss, a), b);
723 return f(DC(
typename D::Dus, a), b);
726 return f(DC(
typename D::Dsi, a), b);
729 return f(DC(
typename D::Dui, a), b);
732 return f(DC(
typename D::Dsl, a), b);
735 return f(DC(
typename D::Dul, a), b);
738 return f(DC(
typename D::Dfloat, a), b);
741 return f(DC(
typename D::Ddouble, a), b);
744 assert(!
"unsupported pixel type in image");
745 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
763 template <
typename F,
typename A,
typename B>
764 static typename F::result_type
filter(
const F& f,
const A& a,
const B& b)
766 typedef typename Binder<B>::Derived D;
768 switch (b.get_pixel_type()) {
770 return _filter(f, a, DC(
typename D::Dbool, b));
773 return _filter(f, a, DC(
typename D::Dsc, b));
776 return _filter(f, a, DC(
typename D::Duc, b));
779 return _filter(f, a, DC(
typename D::Dss, b));
782 return _filter(f, a, DC(
typename D::Dus, b));
785 return _filter(f, a, DC(
typename D::Dsi, b));
788 return _filter(f, a, DC(
typename D::Dui, b));
791 return _filter(f, a, DC(
typename D::Dsl, b));
794 return _filter(f, a, DC(
typename D::Dul, b));
797 return _filter(f, a, DC(
typename D::Dfloat, b));
800 return _filter(f, a, DC(
typename D::Ddouble, b));
803 assert(!
"unsupported pixel type in image");
804 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
810 template <
typename F,
typename A,
typename B>
811 static typename F::result_type _accumulate(F& f,
const A& a,
const B& b)
813 typedef typename Binder<A>::Derived D;
815 switch (a.get_pixel_type()) {
817 return f(DC(
typename D::Dbool, a), b);
820 return f(DC(
typename D::Dsc, a), b);
823 return f(DC(
typename D::Duc, a), b);
826 return f(DC(
typename D::Dss, a), b);
829 return f(DC(
typename D::Dus, a), b);
832 return f(DC(
typename D::Dsi, a), b);
835 return f(DC(
typename D::Dui, a), b);
838 return f(DC(
typename D::Dsl, a), b);
841 return f(DC(
typename D::Dul, a), b);
844 return f(DC(
typename D::Dfloat, a), b);
847 return f(DC(
typename D::Ddouble, a), b);
850 assert(!
"unsupported pixel type in image");
851 throw std::invalid_argument(
"mia::filter: unsupported pixel type in image");
868 template <
typename F,
typename A,
typename B>
869 static typename F::result_type
accumulate(F& f,
const A& a,
const B& b)
871 typedef typename Binder<B>::Derived D;
873 switch (b.get_pixel_type()) {
875 return _accumulate(f, a, DC(
typename D::Dbool, b));
878 return _accumulate(f, a, DC(
typename D::Dsc, b));
881 return _accumulate(f, a, DC(
typename D::Duc, b));
884 return _accumulate(f, a, DC(
typename D::Dss, b));
887 return _accumulate(f, a, DC(
typename D::Dus, b));
890 return _accumulate(f, a, DC(
typename D::Dsi, b));
893 return _accumulate(f, a, DC(
typename D::Dui, b));
896 return _accumulate(f, a, DC(
typename D::Dsl, b));
899 return _accumulate(f, a, DC(
typename D::Dul, b));
902 return _accumulate(f, a, DC(
typename D::Dfloat, b));
905 return _accumulate(f, a, DC(
typename D::Ddouble, b));
908 assert(!
"unsupported pixel type in image");
909 throw std::invalid_argument(
"mia::accumulate: unsupported pixel type in image");
927 return do_filter(image);
934 return do_filter(pimage);
941 return do_filter(*pimage);
949 return do_test_pixeltype_conversion(in_types);
static F::result_type combine_inplace(const F &f, INOUT &inout, const IN &in)
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
static F::result_type filter_equal(const F &f, const B &a, const B &b)
TDataFilterChained< D > Chained
D plugin_data
plugin handler helper type
R result_type
defines the return type of the filter function
TDataFilterPlugin(char const *const name)
Constructor that sets the plug-in name.
#define NS_MIA_END
conveniance define to end the mia namespace
base class for all filer type functors.
static F::result_type _combine_inplace(const F &f, INOUT &inout, const IN &in)
static F::result_type filter(const F &f, const B &b)
result_type filter(std::shared_ptr< D > pimage) const
TFactory< TDataFilter< Image > >::Product Product
static F::result_type filter_and_output(const F &f, const B &a, O &b)
result_type filter(const Image &image) const
static constexpr bool value
std::shared_ptr< TDataFilter< D > > Pointer
pointer type of the data filtered by this filter
std::set< EPixelType > test_pixeltype_conversion(const std::set< EPixelType > &in_types) const
D Image
defines the image type handled by the image filter
The base class for all plug-in created object.
static void filter_equal_inplace(const F &f, const B &a, B &b)
Generic interface class to data filters.
void push_back(Pointer f)
TFilter< std::shared_ptr< D > >::result_type result_type
result type of this filter
static F::result_type accumulate(F &f, const B &data)
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
filter_type plugin_type
plugin handler helper type
TDataFilter< D >::Pointer Pointer
static F::result_type filter_inplace(const F &f, B &b)
Generic image filter plugin base.
This is tha base of all plugins that create "things", like filters, cost functions time step operator...