A.I.M.S algorithms


regularBinnedHisto.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef AIMS_HISTOGRAM_REGULARBINNEDHISTO_H
36 #define AIMS_HISTOGRAM_REGULARBINNEDHISTO_H
37 
39 #include <vector>
40 #include <map>
41 
42 namespace aims
43 {
44 
47  template< typename T>
49  {
50  public:
51 
52  RegularBinnedHistogram( unsigned bins = 0 );
55 
58  void doit( const AimsData<T>& thing );
59  // same but specify min/max to avoid seaching extrema
60  void doit( const AimsData<T>& thing, T mindataval, T maxdataval );
61  unsigned bins() const { return _bins; }
62  void setBins( unsigned bins );
63  T minDataValue() const { return _minvalue; }
64  T maxDataValue() const { return _maxvalue; }
65  std::vector<T> *unique( const AimsData<T>& thing ) const;
66 
67  private:
68  unsigned _bins;
69  T _minvalue;
70  T _maxvalue;
71  };
72 
73 
74  template< typename T> inline
76  : Histogram<T>(), _bins( bins ), _minvalue( 0 ), _maxvalue( 0 )
77  {
78  }
79 
80 
81  template< typename T> inline
83  const RegularBinnedHistogram<T>& other )
84  : Histogram< T >( other ), _bins( other._bins ),
85  _minvalue( other._minvalue ), _maxvalue( other._maxvalue )
86  {
87  }
88 
89 
90  template< typename T> inline
91  void RegularBinnedHistogram<T>::setBins( unsigned bins )
92  {
93  _bins = bins;
94  this->_data = AimsData<int32_t>();
95  }
96 
97 
98  template< typename T > inline
100  {
101  doit( thing, thing.minimum(), thing.maximum() );
102  }
103 
104 
105  template< typename T > inline
106  void RegularBinnedHistogram<T>::doit( const AimsData<T>& thing, T mini,
107  T maxi )
108  {
109  _minvalue = mini;
110  _maxvalue = maxi;
111 
112  if( _bins == 0 )
113  {
114  _bins = 256;
115  }
116 
117  this->_data = AimsData<int32_t>( _bins );
118  this->_data = 0;
119  typename AimsData<T>::const_iterator iv, fv=thing.end();
120  double scl = (double) _bins / (double) ( maxi - mini );
121  double x;
122  int y;
123 
124  int iy, iz, it, nx = thing.dimX(), ny = thing.dimY(), nz = thing.dimZ(),
125  nt = thing.dimT();
126  for( it=0; it<nt; ++it )
127  for( iz=0; iz<nz; ++iz )
128  for( iy=0; iy<ny; ++iy )
129  for( iv=&thing( 0, iy, iz, it ), fv=iv+nx; iv!=fv; ++iv )
130  {
131 // std::cout << "iv: " << iv << ", nx: " << nx << ", ny: " << ny << ", nz: " << nz << ", nt: " << nt << ", iv+1: " << &thing( 1, iy, iz, it ) << std::endl;
132  x = (double) ( (double) (*iv) - mini ) * scl;
133  y = (int) x;
134  if( y < 0 )
135  {}
136  else if( y >= (int) _bins )
137  {
138  if( x == (int) _bins )
139  ++this->_data( _bins-1 );
140  }
141  else
142  ++this->_data( y );
143  }
144  }
145 
146 
147  template< typename T > inline
148  std::vector<T> *
150  {
151  std::map<T, unsigned> vals;
152  typename AimsData<T>::const_iterator iv, fv=thing.end();
153  for( iv=thing.begin(); iv!=fv; ++iv )
154  {
155  ++vals[*iv];
156  }
157  std::vector<T> *res = new std::vector<T>( vals.size() );
158  typename std::map<T, unsigned>::iterator im, e = vals.end();
159  typename std::vector<T>::iterator i = res->begin();
160  for( im=vals.begin(); im!=e; ++im, ++i )
161  *i = im->first;
162  return res;
163  }
164 
165 }
166 
167 #endif
T minimum() const
const T * const_iterator
int dimX() const
iterator begin()
int dimT() const
Histogram container class, with a specified number of regular bins.
T maximum() const
RegularBinnedHistogram(unsigned bins=0)
void doit(const AimsData< T > &thing)
classical histogram computation function.
Base class of histogram container class.
Definition: histogram.h:42
std::vector< T > * unique(const AimsData< T > &thing) const
int dimZ() const
int dimY() const
iterator end()