25 #ifndef mia_internal_filter_chain_hh 26 #define mia_internal_filter_chain_hh 39 template <
typename Handler>
41 typedef typename Handler::ProductPtr PFilter;
45 typedef typename PFilter::element_type::plugin_data::Pointer
PData;
80 void init(
const char *filters[],
int nfilters);
81 std::vector<PFilter> m_chain;
89 template <
typename Handler>
90 typename Handler::ProductPtr __get_filter(
const Handler& ,
typename Handler::ProductPtr
filter)
95 template <
typename Handler>
96 typename Handler::ProductPtr __get_filter(
const Handler& h,
const char *
filter)
98 return h.produce(filter);
101 template <
typename Handler>
102 typename Handler::ProductPtr __get_filter(
const Handler& h,
const std::string& filter)
104 return h.produce(filter);
107 template <
typename PData,
typename Handler,
typename T>
108 PData __run_filters(
PData image,
const Handler& h, T filter_descr)
110 auto f = __get_filter(h, filter_descr);
111 return f->filter(image);
114 template <
typename PData,
typename Handler,
typename T,
typename... Filters>
115 PData __run_filters(
PData image,
const Handler& h, T filter_descr, Filters ...filters)
117 image = __run_filters(image, h, filter_descr);
118 return __run_filters(image, h, filters...);
133 template <
typename PData,
typename... Filters>
136 typedef std::shared_ptr<TDataFilter<typename PData::element_type> > PFilter;
137 typedef typename FactoryTrait<PFilter>::type Handler;
139 return __run_filters(image, Handler::instance(), filters...);
142 template <
typename Handler>
145 for(
int i = 0; i < nfilters; ++i) {
146 m_chain[i] = Handler::instance().produce(filters[i]);
148 throw create_exception<std::invalid_argument>(
"Can't create filter from '", filters[i],
"'");
154 template <
typename Handler>
158 init(filters, nfilters);
161 template <
typename Handler>
163 m_chain(filters.size())
165 std::transform(filters.begin(), filters.end(), m_chain.begin(),
166 [](
const std::string& s){
return Handler::instance().produce(s); });
169 template <
typename Handler>
172 auto f = Handler::instance().produce(filter);
174 m_chain.insert(m_chain.begin(), f);
176 throw create_exception<std::invalid_argument>(
"Can't create filter from '",
filter,
"'");
179 template <
typename Handler>
182 auto f = Handler::instance().produce(filter);
184 m_chain.push_back(f);
186 throw create_exception<std::invalid_argument>(
"Can't create filter from '",
filter,
"'");
189 template <
typename Handler>
193 for (
auto i = m_chain.begin(); i != m_chain.end(); ++i) {
194 input = (*i)->filter(input);
199 template <
typename Handler>
202 return m_chain.empty();
void push_back(const char *filter)
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
static F::result_type filter(const F &f, const B &b)
void push_front(const char *filter)
TFilterChain(const char *filters[], int nfilters)
PFilter::element_type::plugin_data::Pointer PData
the pointer type of the data to be filtered
PData run(PData input) const
PData run_filters(PData image, Filters... filters)
run a chain of filters on an input image
create and use a chain of filters
#define NS_MIA_END
conveniance define to end the mia namespace