aimstil  5.0.5
histogram.h
Go to the documentation of this file.
1 #ifndef _TIL_HISTOGRAM_H_
2 #define _TIL_HISTOGRAM_H_
3 
4 // includes from STL
5 #include <map>
6 
7 // includes from BOOST
8 #include <boost/call_traits.hpp>
9 #include <boost/type_traits.hpp>
10 #include <boost/utility/enable_if.hpp>
11 
12 // includes from TIL
13 #include "til/Accumulator.h"
14 
15 // includes from TIL
16 //#include "cat2type.h"
17 #include "globalTraits.h"
18 
19 namespace til
20 {
21  namespace policy
22  {
23 
27 /*
28  //template < typename T, typename TCount, template <typename,typename> class TMap = std::map >
29  struct Accumulation_MapHistogram
30  {
31  typedef TMap<TCount,T> Map;
32 
33  void operator()(Map & m, const T & value)
34  {
35  // look if current value is already present in the histogram
36  typename Map::iterator i = m.find(value);
37  if (i == m.end())
38  {
39  // If not, add it in the histogram, and set count to one.
40  m[value] = TCount(1);
41  }
42  else
43  {
44  // Otherwise, simply increase its count.
45  ++(i->second);
46  }
47  }
48  };
49  }
50 */
51  // create Accumulation_MapHistogram_def to avoid Accumulation_MapHistogram<T,TCount,TMap> calls
53  {
54  typedef std::map<std::size_t, std::size_t > Map;
55 
56  void operator()(Map & m, const std::size_t & value)
57  {
58  // look if current value is already present in the histogram
59  Map::iterator i = m.find(value);
60  if (i == m.end())
61  {
62  // If not, add it in the histogram, and set count to one.
63  m[value] = 1;
64  }
65  else
66  {
67  // Otherwise, simply increase its count.
68  ++(i->second);
69  }
70  }
71  };
72 
73  }
74 
80 /*
81  template < typename T, typename TCount = unsigned int, template <typename,typename> class TMap = std::map >
82  class MapHistogram : public Accumulator<T, TMap<TCount, T>, policy::Accumulation_MapHistogram<T,TCount,TMap> >
83  {
84  public: // typedefs
85 
86  typedef TMap<T, TCount> Map;
87  };
88 */
89  // create MapHistogram_def to avoid MapHistogram<std::size_t> calls
90  // not allowed in new gcc version
91  class MapHistogram_def : public Accumulator<std::size_t, std::map<std::size_t, std::size_t>, policy::Accumulation_MapHistogram_def >
92  {
93  public: // typedefs
94 
95  typedef std::map<std::size_t, std::size_t> Map;
96  };
97 
98 
99 
100 /*
101  template < typename T, typename TCount, template <typename,typename> class TMap >
102  void print(const MapHistogram_def & h)
103  {
104  typename MapHistogram<T,TCount,TMap>::Map::const_iterator iH = h.get().begin();
105  for (; iH != h.get().end(); ++iH)
106  {
107  std::cout << iH->first << " : " << iH->second << std::endl;
108  }
109  }
110 */
111  // create printf_def to replace print(const MapHistogram_def & h) method
112  void print_def(const MapHistogram_def & h);
113 
114  void save_def(const MapHistogram_def & h, std::string filename, float valueFactor);
115 
117  {
118  public:
119 
120  MapHistogram_float(float range);
122  void accumulate(float value);
123  void print();
124  void save(std::string filename, float valueFactor);
125  protected:
126 
128  float _range;
129  };
130 
131 } // namespace
132 
133 #endif /*_TIL_HISTOGRAM_H_*/
void operator()(Map &m, const std::size_t &value)
Definition: histogram.h:56
void print(const Affine< T > &a)
void print_def(const MapHistogram_def &h)
void save_def(const MapHistogram_def &h, std::string filename, float valueFactor)
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
MapHistogram_def h
Definition: histogram.h:127
Compute a histogram by means of a map.
Definition: histogram.h:91
A class to accumulate value.
Definition: Accumulator.h:81
Histogram accumulation policy for Accumulator.
Definition: histogram.h:52
std::map< std::size_t, std::size_t > Map
Definition: histogram.h:54
std::map< std::size_t, std::size_t > Map
Definition: histogram.h:95