aimstil  5.0.5
RecursiveFilterSum.h
Go to the documentation of this file.
1 #ifndef TIL_RECURSIVE_FILTER_SUM_H
2 #define TIL_RECURSIVE_FILTER_SUM_H
3 
4 // TODO: rename into bidirectionalFilter
5 
6 // includes from STL
7 #include <cassert>
8 #include <vector>
9 
10 // includes from BOOST
11 #include <boost/type_traits.hpp>
12 
13 // includes from TIL library
14 #include "til/til_common.h"
15 #include "til/templateTools.h"
16 
17 
18 namespace til {
19 
21  // TODO: Could be templated w.r.t filter...
22 template < class TRecursiveFilter1, class TRecursiveFilter2 >
24 {
25 public: // typedef
26 
28  // NB: see also private rules
29  typedef typename TRecursiveFilter1::T T;
30 
31 public: // constuctors & destructor
32 
34  const TRecursiveFilter1 & filter1,
35  const TRecursiveFilter2 & filter2)
36  {
37  m_removeOverlap = true;
38  m_filter1 = filter1;
39  m_filter2 = filter2;
40  }
41 
42 public: // methods
43 
44  // Apply filter to 'in' (of given length), result outputed in 'out'
45  // out has to be allocated with the same size as in
46  void apply(const std::vector<T> &in, std::vector<T> &out) const
47  {
48  // Make sure that input and output vectors have same size
49  assert(in.size() == out.size());
50 
51  if (m_removeOverlap)
52  {
53  // TODO: C'mon, I'm sure there is an STL algorithm to do that...
54  typename std::vector<T>::const_iterator iIn = in.begin();
55  typename std::vector<T>::iterator iOut = out.begin();
56  for (; iIn != in.end(); ++iIn, ++iOut)
57  {
58  *iOut = - *iIn * this->bias();
59  }
60  }
61 
62  m_filter1.apply(in, out);
63  m_filter2.apply(in, out);
64  }
65 private: // rules
66 
67  // Check that types of both filters are equal
68  typedef typename enable_if<boost::is_same<typename TRecursiveFilter1::T, typename TRecursiveFilter2::T> >::type Rule_both_filters_have_same_type;
69  // TODO: also check that there are a forward and a backward filter
70 
71 private: // methods
72 
73  // Pb: the value at zero is computed two times, once forward, once
74  // backward. So it has to be removed.
75  // Theoretically this value is m_mif[0] = m_mib[0]
76  // But this equality may not hold (this is the case for
77  // Gaussian 1st derivative for example).
78  // So the mean is taken here.
79 
80  T bias() const { return (m_filter1.getMI()[0] + m_filter2.getMI()[0]) / 2.0; }
81 
82  void removeOverlap(bool flag) { m_removeOverlap = flag; }
83 
84 
85 private: // data
86 
87  bool m_removeOverlap;
88 
89  TRecursiveFilter1 m_filter1;
90  TRecursiveFilter2 m_filter2;
91 };
92 
93 
94 }
95 
96 #endif
97 
Sum of two recursive filters, a forward and a backward one.
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
void apply(const std::vector< T > &in, std::vector< T > &out) const
RecursiveFilterSum(const TRecursiveFilter1 &filter1, const TRecursiveFilter2 &filter2)
General macros, definitions and functions.
TRecursiveFilter1::T T
Type of the filter.
Collects template tools used for library implementation.