A.I.M.S


bucket.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  * Bucket class
36  */
37 #ifndef AIMS_BUCKET_BUCKET_H
38 #define AIMS_BUCKET_BUCKET_H
39 
41 #include <aims/bucket/item.h>
42 #include <aims/data/pheader.h>
43 #include <iostream>
44 #include <map>
45 #include <list>
46 
47 
48 template <class T> class AimsBucket;
49 
50 
51 template <class T>
52 AIMSDATA_API std::ostream& operator << (std::ostream& out,
53  const AimsBucket<T>& thing);
54 
55 namespace aims
56 {
57  template<class T> class BucketMap;
58 }
59 
60 
67 template <class T>
68 class AimsBucket
69  : public std::map< int , std::list< AimsBucketItem<T> > >
70 {
71 public:
72  typedef typename std::map<int, std::list<AimsBucketItem<T> > >::iterator
74  typedef typename
75  std::map<int, std::list<AimsBucketItem<T> > >::const_iterator
77  typedef typename std::map<int, std::list<AimsBucketItem<T> > >::key_type
79 
80  AimsBucket() : std::map< int , std::list< AimsBucketItem<T> > >()
81  { }
82  AimsBucket( const AimsBucket<T> & other )
83  : std::map<int,std::list< AimsBucketItem<T> > >( other ),
84  _header( other._header ) {}
85  AimsBucket( const aims::BucketMap<T> & other );
86  virtual ~AimsBucket() { }
87 
89 
100  inline void push_front(const AimsBucketItem<T>& item);
101  inline void push_back(const AimsBucketItem<T>& item);
102 
103  inline void pop_front();
104  inline void pop_back();
105 
106  // because map[] does not have const operator [ ] : warning at compil.
107  inline const std::list< AimsBucketItem<T> >&
108  operator [] ( const key_type& n ) const
109  { return find( n )->second; }
110  inline std::list< AimsBucketItem<T> >& operator [] ( const key_type& n )
111  { return
112  (*((this->insert
113  (typename std::map< int, std::list< AimsBucketItem<T> > >::value_type
114  (n, std::list< AimsBucketItem<T> >()))).first)).second; }
115 
117  inline float sizeX() const;
119  inline float sizeY() const;
121  inline float sizeZ() const;
123  inline float sizeT() const;
124 
126  inline void setSizeX(float sizex);
128  inline void setSizeY(float sizey);
130  inline void setSizeZ(float sizez);
132  inline void setSizeT(float sizet);
134  inline void setSizeXYZT(float sizex,float sizey,float sizez,float sizet);
135 
137  inline void erase();
139 
140  inline const aims::PythonHeader &header() const { return _header; }
141  inline aims::PythonHeader &header() { return _header; }
142  void setHeader( const aims::PythonHeader &hdr ) { _header = hdr; }
143 
144  friend
145  std::ostream& operator << <> (std::ostream& out,
146  const AimsBucket<T>& thing);
147 
148 protected:
150 };
151 
152 
153 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
154 
155 namespace carto
156 {
157 
158  template<typename T> class DataTypeCode<AimsBucket<T> >
159  {
160  public:
161  static std::string objectType()
162  { return "Bucket"; }
163  static std::string dataType()
164  { return DataTypeCode<T>::dataType(); }
165  static std::string name()
166  {
167  return std::string("bucket of ") + DataTypeCode< T >::name();
168  }
169  };
170 
171 }
172 
173 #endif // DOXYGEN_HIDE_INTERNAL_CLASSES
174 
175 
176 template <class T> inline
178 { (*this)[0].push_front(item);
179 }
180 
181 
182 template <class T> inline
184 { (*this)[0].push_back(item);
185 }
186 
187 
188 template <class T> inline
190 { (*this)[0].pop_front();
191 }
192 
193 
194 template <class T> inline
196 { (*this)[0].pop_back();
197 }
198 
199 
200 template <class T> inline float AimsBucket<T>::sizeX() const
201 {
202  std::vector<float> vs;
203  _header.getProperty( "voxel_size", vs );
204  if( vs.empty() )
205  return 1.;
206  return vs[0];
207 }
208 
209 
210 template <class T> inline float AimsBucket<T>::sizeY() const
211 {
212  std::vector<float> vs;
213  _header.getProperty( "voxel_size", vs );
214  if( vs.size() < 2 )
215  return 1.;
216  return vs[1];
217 }
218 
219 
220 template <class T> inline float AimsBucket<T>::sizeZ() const
221 {
222  std::vector<float> vs;
223  _header.getProperty( "voxel_size", vs );
224  if( vs.size() < 3 )
225  return 1.;
226  return vs[2];
227 }
228 
229 
230 template <class T> inline float AimsBucket<T>::sizeT() const
231 {
232  std::vector<float> vs;
233  _header.getProperty( "voxel_size", vs );
234  if( vs.size() < 4 )
235  return 1.;
236  return vs[3];
237 }
238 
239 
240 template <class T> inline
241 void AimsBucket<T>::setSizeX(float sizex)
242 {
243  ASSERT(sizex>0);
244  std::vector<float> vs;
245  _header.getProperty( "voxel_size", vs );
246  while( vs.size() < 4 )
247  vs.push_back( 1. );
248  vs[0] = sizex;
249  _header.setProperty( "voxel_size", vs );
250 }
251 
252 
253 template <class T> inline
254 void AimsBucket<T>::setSizeY(float sizey)
255 {
256  ASSERT(sizey>0);
257  std::vector<float> vs;
258  _header.getProperty( "voxel_size", vs );
259  while( vs.size() < 4 )
260  vs.push_back( 1. );
261  vs[1] = sizey;
262  _header.setProperty( "voxel_size", vs );
263 }
264 
265 
266 template <class T> inline
267 void AimsBucket<T>::setSizeZ(float sizez)
268 {
269  ASSERT(sizez>0);
270  std::vector<float> vs;
271  _header.getProperty( "voxel_size", vs );
272  while( vs.size() < 4 )
273  vs.push_back( 1. );
274  vs[2] = sizez;
275  _header.setProperty( "voxel_size", vs );
276 }
277 
278 
279 template <class T> inline
280 void AimsBucket<T>::setSizeT(float sizet)
281 {
282  ASSERT(sizet>0);
283  std::vector<float> vs;
284  _header.getProperty( "voxel_size", vs );
285  while( vs.size() < 4 )
286  vs.push_back( 1. );
287  vs[3] = sizet;
288  _header.setProperty( "voxel_size", vs );
289 }
290 
291 
292 template <class T> inline
293 void AimsBucket<T>::setSizeXYZT( float sizex, float sizey, float sizez,
294  float sizet)
295 {
296  std::vector<float> vs(4);
297  vs[0] = sizex;
298  vs[1] = sizey;
299  vs[2] = sizez;
300  vs[3] = sizet;
301  _header.setProperty( "voxel_size", vs );
302 }
303 
304 
305 template <class T> inline
307 {
308  typename AimsBucket<T>::iterator it;
309  for (it=this->begin();it!=this->end();it++)
310  ((*it).second).erase( ((*it).second).begin() , ((*it).second).end() );
311  std::map< int , std::list< AimsBucketItem<T> > >::erase( this->begin(), this->end() );
312 }
313 
314 
315 template <class T> inline
316 std::ostream& operator << (std::ostream& out, const AimsBucket<T>& thing)
317 {
318  out << "{";
319 
320  typename AimsBucket<T>::const_iterator it1;
321  typename std::list< AimsBucketItem<T> >::const_iterator it2;
322 
323  for (it1=thing.begin();it1!=thing.end();it1++)
324  {
325  out << "{";
326  out << "t=" << (*it1).first << ",";
327  for (it2=((*it1).second).begin();it2!=((*it1).second).end();it2++)
328  out << *it2 << ",";
329  out << "NULL},";
330  }
331 
332  return out << "NULL}" << std::flush;
333 }
334 
335 
336 #include <aims/bucket/bucketMap.h>
337 
338 
339 #endif
AimsBucket< T > & operator=(const aims::BucketMap< T > &)
Definition: bucketMap.h:379
void push_front(const AimsBucketItem< T > &item)
Function redefined to omit time.
Definition: bucket.h:177
std::string dataType()
void setSizeY(float sizey)
sets the Y resolution of the data in mm
Definition: bucket.h:254
std::map< int, std::list< AimsBucketItem< T > > >::const_iterator const_iterator
Definition: bucket.h:76
Attributed python-like header, stores all needed information about an object, currently used for volu...
Definition: pheader.h:51
float sizeX() const
returns the X resolution in mm
Definition: bucket.h:200
void setHeader(const aims::PythonHeader &hdr)
Definition: bucket.h:142
AIMSDATA_API std::ostream & operator<<(std::ostream &out, const AimsBucket< T > &thing)
Definition: bucket.h:316
float sizeT() const
returns the T resolution in mm
Definition: bucket.h:230
void setSizeXYZT(float sizex, float sizey, float sizez, float sizet)
sets X,Y,Z and T resolutions of the data in mm
Definition: bucket.h:293
#define AIMSDATA_API
void erase()
Empty the whole map.
Definition: bucket.h:306
aims::PythonHeader & header()
Definition: bucket.h:141
const aims::PythonHeader & header() const
Definition: bucket.h:140
void push_back(const AimsBucketItem< T > &item)
Definition: bucket.h:183
std::map< int, std::list< AimsBucketItem< T > > >::key_type key_type
Definition: bucket.h:78
std::string name()
static std::string dataType()
Definition: bucket.h:163
void setSizeX(float sizex)
sets the X resolution of the data in mm
Definition: bucket.h:241
An alternate, ordered, representation for buckets (voxels lists).
Definition: bucket.h:57
std::map< int, std::list< AimsBucketItem< T > > >::iterator iterator
Definition: bucket.h:73
The bucket base class to manage packages of points associated to their value during time...
Definition: bucket.h:48
void setSizeT(float sizet)
sets the T resolution of the data in mm
Definition: bucket.h:280
virtual ~AimsBucket()
Definition: bucket.h:86
aims::PythonHeader _header
Definition: bucket.h:149
AimsBucket(const AimsBucket< T > &other)
Definition: bucket.h:82
void pop_back()
Definition: bucket.h:195
const std::list< AimsBucketItem< T > > & operator[](const key_type &n) const
Definition: bucket.h:108
The template base class for all types of bucket items.
Definition: item.h:47
static std::string objectType()
Definition: bucket.h:161
float sizeY() const
returns the Y resolution in mm
Definition: bucket.h:210
AimsBucket()
Definition: bucket.h:80
float sizeZ() const
returns the Z resolution in mm
Definition: bucket.h:220
void setSizeZ(float sizez)
sets the Z resolution of the data in mm
Definition: bucket.h:267
void pop_front()
Definition: bucket.h:189
#define ASSERT(EX)