A.I.M.S algorithms


simpleHisto.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_SIMPLEHISTO_H
36 #define AIMS_HISTOGRAM_SIMPLEHISTO_H
37 
39 
42 template< class T>
43 class SimpleHistogram : public Histogram<T>
44 {
45  public:
46 
53  : Histogram< T >( other ) { }
55  virtual ~SimpleHistogram() { }
57 
63  void doit( const AimsData<T>& thing );
64 
68  void rebin( int size );
75  void rebin( int size, AimsData<int32_t>::iterator beg,
78 };
79 
80 
81 template< class T > inline
83 {
84  AimsData<int32_t> res( 1 << 8 * sizeof( T ) );
85 
86  typename AimsData<T>::const_iterator it;
88 
89  this->_minValid = (int)thing.minimum();
90  this->_maxValid = (int)thing.maximum();
91 
92  this->_nPoints = thing.dimX() * thing.dimY() * thing.dimZ() * thing.dimT();
93 
94  it = thing.begin() + thing.oFirstPoint();
95 
96  int x, y, z, t;
97  for ( t=thing.dimT(); t--; it += thing.oSliceBetweenVolume() )
98  for ( z=thing.dimZ(); z--; it += thing.oLineBetweenSlice() )
99  for ( y=thing.dimY(); y--; it += thing.oPointBetweenLine() )
100  for ( x=thing.dimX(); x--; it++ )
101  dest[ (int)*it - this->_minValid ]++;
102 
103  this->_data = res;
104 }
105 
106 
107 template< class T > inline
109 {
110  rebin( size, this->_data.begin() , this->_data.end() );
111 }
112 
113 
114 template< class T > inline
116  typename AimsData<int32_t>::iterator end )
117 {
118  rebin( end - beg, beg, end );
119 }
120 
121 
122 template< class T > inline
125 {
126  int i, sum, length = end - beg;
127 
128  ASSERT( size <= length );
129 
130  int coef = (int)ceil( (double)length / (double)size );
131  AimsData<int32_t> res( size );
132 
133  this->_nPoints = 0;
134 
135  AimsData<int32_t>::iterator it2, it = beg;
136  for ( it2=res.begin(); it2!=res.end(); )
137  {
138  sum = 0;
139 
140  for ( i = coef; i-- && it != end; )
141  sum += *it++;
142 
143  *it2++ = sum;
144  this->_nPoints += sum;
145  }
146 
147  int tmpMin = this->_minValid;
148 
149  this->_minValid = this->_maxValid = tmpMin /coef;
150 
151  for ( it2 = res.begin(); *it2 == 0 && it2 != res.end(); it2++ )
152  this->_minValid = it2 - res.begin() + tmpMin / coef;
153 
154  for ( ; it2 != res.end(); it2++ )
155  if (*it2)
156  this->_maxValid = it2 - res.begin() + tmpMin / coef;
157 
158  this->_data = res;
159 }
160 
161 
162 template <>
163 inline
165 {
166  int size = 65536;
167  AimsData<int32_t> res( size );
168 
170 
171  float minh = thing.minimum();
172  float maxh = thing.maximum();
173  float div = maxh - minh;
174 
175  if ( ( div < (float)size ) && ( div > 1.0f ) )
176  {
177  div = (float)size;
178  this->_minValid = (int)minh;
179  this->_maxValid = (int)maxh;
180  }
181  else
182  {
183  this->_minValid = 0;
184  this->_maxValid = size - 1;
185  }
186 
187  this->_nPoints = thing.dimX() * thing.dimY() * thing.dimZ() * thing.dimT();
188 
189  it = thing.begin() + thing.oFirstPoint();
190 
191  int x, y, z, t;
192  for ( t=thing.dimT(); t--; it += thing.oSliceBetweenVolume() )
193  for ( z=thing.dimZ(); z--; it += thing.oLineBetweenSlice() )
194  for ( y=thing.dimY(); y--; it += thing.oPointBetweenLine() )
195  for ( x=thing.dimX(); x--; it++ )
196  {
197  int p = (int)( (float) size * ( *it - minh ) / div );
198  if( p < 0 )
199  p = 0;
200  else if( p >= size )
201  p = size - 1;
202  res[ p ]++;
203  }
204 
205  this->_data = res;
206 }
207 
208 
209 template <>
210 inline
212 {
213  int size = 65536;
214  AimsData<int32_t> res( size );
215 
217  AimsData<int32_t>::iterator dest = res.begin();
218 
219  double minh = thing.minimum();
220  double maxh = thing.maximum();
221  double div = maxh - minh;
222 
223  if ( ( div < (float)size ) && ( div > 1.0f ) )
224  {
225  div = (double)size;
226  this->_minValid = (int)minh;
227  this->_maxValid = (int)maxh;
228  }
229  else
230  {
231  this->_minValid = 0;
232  this->_maxValid = size - 1;
233  }
234 
235  this->_nPoints = thing.dimX() * thing.dimY() * thing.dimZ() * thing.dimT();
236 
237  it = thing.begin() + thing.oFirstPoint();
238 
239  int x, y, z, t;
240  for ( t=thing.dimT(); t--; it += thing.oSliceBetweenVolume() )
241  for ( z=thing.dimZ(); z--; it += thing.oLineBetweenSlice() )
242  for ( y=thing.dimY(); y--; it += thing.oPointBetweenLine() )
243  for ( x=thing.dimX(); x--; it++ )
244  dest[ (int)( (double)size * ( *it - minh ) / div ) ]++;
245 
246  this->_data = res;
247 }
248 
249 #endif
T minimum() const
const T * const_iterator
int dimX() const
iterator begin()
int dimT() const
int oPointBetweenLine() const
T maximum() const
virtual ~SimpleHistogram()
destructor.
Definition: simpleHisto.h:55
Classical histogram container class.
Definition: simpleHisto.h:43
SimpleHistogram(const SimpleHistogram< T > &other)
copy constructor.
Definition: simpleHisto.h:52
SimpleHistogram()
constructor. Does nothing.
Definition: simpleHisto.h:50
Base class of histogram container class.
Definition: histogram.h:42
int oSliceBetweenVolume() const
int oLineBetweenSlice() const
void doit(const AimsData< T > &thing)
classical histogram computation function.
Definition: simpleHisto.h:82
void rebin(int size)
rebinning to a specific result vector size.
Definition: simpleHisto.h:108
int dimZ() const
int dimY() const
iterator end()
#define ASSERT(EX)
int oFirstPoint() const