aimsdata  5.1.2
Neuroimaging data handling
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  inline std::vector<float> getVoxelSize() const;
125 
127  inline void setSizeX(float sizex);
129  inline void setSizeY(float sizey);
131  inline void setSizeZ(float sizez);
133  inline void setSizeT(float sizet);
135  inline void setSizeXYZT(float sizex,float sizey,float sizez,float sizet);
136  inline void setSizeXYZT( const std::vector<float> & vsize );
137  inline void setVoxelSize( float sizex, float sizey, float sizez,
138  float sizet )
139  { setSizeXYZT( sizex, sizey, sizez, sizet ); }
140  inline void setVoxelSize( const std::vector<float> & vsize )
141  { setSizeXYZT( vsize ); }
142 
144  inline void erase();
146 
147  inline const aims::PythonHeader &header() const { return _header; }
148  inline aims::PythonHeader &header() { return _header; }
149  void setHeader( const aims::PythonHeader &hdr ) { _header = hdr; }
150 
151  friend
152  std::ostream& operator << <> (std::ostream& out,
153  const AimsBucket<T>& thing);
154 
155 protected:
157 };
158 
159 
160 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
161 
162 namespace carto
163 {
164 
165  template<typename T> class DataTypeCode<AimsBucket<T> >
166  {
167  public:
168  static std::string objectType()
169  { return "Bucket"; }
170  static std::string dataType()
171  { return DataTypeCode<T>::dataType(); }
172  static std::string name()
173  {
174  return std::string("bucket of ") + DataTypeCode< T >::name();
175  }
176  };
177 
178 }
179 
180 #endif // DOXYGEN_HIDE_INTERNAL_CLASSES
181 
182 
183 template <class T> inline
185 { (*this)[0].push_front(item);
186 }
187 
188 
189 template <class T> inline
191 { (*this)[0].push_back(item);
192 }
193 
194 
195 template <class T> inline
197 { (*this)[0].pop_front();
198 }
199 
200 
201 template <class T> inline
203 { (*this)[0].pop_back();
204 }
205 
206 
207 template <class T> inline std::vector<float>
209 {
210  std::vector<float> vs;
211  _header.getProperty( "voxel_size", vs );
212  while( vs.size() < 4 )
213  vs.push_back( 1. );
214  return vs;
215 }
216 
217 
218 template <class T> inline float AimsBucket<T>::sizeX() const
219 {
220  std::vector<float> vs;
221  _header.getProperty( "voxel_size", vs );
222  if( vs.empty() )
223  return 1.;
224  return vs[0];
225 }
226 
227 
228 template <class T> inline float AimsBucket<T>::sizeY() const
229 {
230  std::vector<float> vs;
231  _header.getProperty( "voxel_size", vs );
232  if( vs.size() < 2 )
233  return 1.;
234  return vs[1];
235 }
236 
237 
238 template <class T> inline float AimsBucket<T>::sizeZ() const
239 {
240  std::vector<float> vs;
241  _header.getProperty( "voxel_size", vs );
242  if( vs.size() < 3 )
243  return 1.;
244  return vs[2];
245 }
246 
247 
248 template <class T> inline float AimsBucket<T>::sizeT() const
249 {
250  std::vector<float> vs;
251  _header.getProperty( "voxel_size", vs );
252  if( vs.size() < 4 )
253  return 1.;
254  return vs[3];
255 }
256 
257 
258 template <class T> inline
259 void AimsBucket<T>::setSizeX(float sizex)
260 {
261  ASSERT(sizex>0);
262  std::vector<float> vs;
263  _header.getProperty( "voxel_size", vs );
264  while( vs.size() < 4 )
265  vs.push_back( 1. );
266  vs[0] = sizex;
267  _header.setProperty( "voxel_size", vs );
268 }
269 
270 
271 template <class T> inline
272 void AimsBucket<T>::setSizeY(float sizey)
273 {
274  ASSERT(sizey>0);
275  std::vector<float> vs;
276  _header.getProperty( "voxel_size", vs );
277  while( vs.size() < 4 )
278  vs.push_back( 1. );
279  vs[1] = sizey;
280  _header.setProperty( "voxel_size", vs );
281 }
282 
283 
284 template <class T> inline
285 void AimsBucket<T>::setSizeZ(float sizez)
286 {
287  ASSERT(sizez>0);
288  std::vector<float> vs;
289  _header.getProperty( "voxel_size", vs );
290  while( vs.size() < 4 )
291  vs.push_back( 1. );
292  vs[2] = sizez;
293  _header.setProperty( "voxel_size", vs );
294 }
295 
296 
297 template <class T> inline
298 void AimsBucket<T>::setSizeT(float sizet)
299 {
300  ASSERT(sizet>0);
301  std::vector<float> vs;
302  _header.getProperty( "voxel_size", vs );
303  while( vs.size() < 4 )
304  vs.push_back( 1. );
305  vs[3] = sizet;
306  _header.setProperty( "voxel_size", vs );
307 }
308 
309 
310 template <class T> inline
311 void AimsBucket<T>::setSizeXYZT( float sizex, float sizey, float sizez,
312  float sizet)
313 {
314  std::vector<float> vs(4);
315  vs[0] = sizex;
316  vs[1] = sizey;
317  vs[2] = sizez;
318  vs[3] = sizet;
319  _header.setProperty( "voxel_size", vs );
320 }
321 
322 
323 template <class T> inline
324 void AimsBucket<T>::setSizeXYZT( const std::vector<float> & vsize )
325 {
326  std::vector<float> vs = vsize;
327  while( vs.size() < 4 )
328  vs.push_back( 1. );
329  _header.setProperty( "voxel_size", vs );
330 }
331 
332 
333 template <class T> inline
335 {
336  typename AimsBucket<T>::iterator it;
337  for (it=this->begin();it!=this->end();it++)
338  ((*it).second).erase( ((*it).second).begin() , ((*it).second).end() );
339  std::map< int , std::list< AimsBucketItem<T> > >::erase( this->begin(), this->end() );
340 }
341 
342 
343 template <class T> inline
344 std::ostream& operator << (std::ostream& out, const AimsBucket<T>& thing)
345 {
346  out << "{";
347 
348  typename AimsBucket<T>::const_iterator it1;
349  typename std::list< AimsBucketItem<T> >::const_iterator it2;
350 
351  for (it1=thing.begin();it1!=thing.end();it1++)
352  {
353  out << "{";
354  out << "t=" << (*it1).first << ",";
355  for (it2=((*it1).second).begin();it2!=((*it1).second).end();it2++)
356  out << *it2 << ",";
357  out << "NULL},";
358  }
359 
360  return out << "NULL}" << std::flush;
361 }
362 
363 
364 #include <aims/bucket/bucketMap.h>
365 
366 
367 #endif
#define AIMSDATA_API
#define ASSERT(EX)
AIMSDATA_API std::ostream & operator<<(std::ostream &out, const AimsBucket< T > &thing)
Definition: bucket.h:344
The template base class for all types of bucket items.
Definition: item.h:63
The bucket base class to manage packages of points associated to their value during time.
Definition: bucket.h:70
virtual ~AimsBucket()
Definition: bucket.h:86
AimsBucket()
Definition: bucket.h:80
aims::PythonHeader & header()
Definition: bucket.h:148
float sizeX() const
returns the X resolution in mm
Definition: bucket.h:218
const std::list< AimsBucketItem< T > > & operator[](const key_type &n) const
Definition: bucket.h:108
AimsBucket(const AimsBucket< T > &other)
Definition: bucket.h:82
void setSizeX(float sizex)
sets the X resolution of the data in mm
Definition: bucket.h:259
float sizeY() const
returns the Y resolution in mm
Definition: bucket.h:228
std::map< int, std::list< AimsBucketItem< T > > >::const_iterator const_iterator
Definition: bucket.h:76
void setVoxelSize(float sizex, float sizey, float sizez, float sizet)
Definition: bucket.h:137
void pop_back()
Definition: bucket.h:202
void push_back(const AimsBucketItem< T > &item)
Definition: bucket.h:190
void setVoxelSize(const std::vector< float > &vsize)
Definition: bucket.h:140
aims::PythonHeader _header
Definition: bucket.h:156
void pop_front()
Definition: bucket.h:196
std::vector< float > getVoxelSize() const
Definition: bucket.h:208
void setSizeY(float sizey)
sets the Y resolution of the data in mm
Definition: bucket.h:272
void push_front(const AimsBucketItem< T > &item)
Function redefined to omit time.
Definition: bucket.h:184
float sizeZ() const
returns the Z resolution in mm
Definition: bucket.h:238
void setHeader(const aims::PythonHeader &hdr)
Definition: bucket.h:149
float sizeT() const
returns the T resolution in mm
Definition: bucket.h:248
void setSizeT(float sizet)
sets the T resolution of the data in mm
Definition: bucket.h:298
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:311
AimsBucket< T > & operator=(const aims::BucketMap< T > &)
Definition: bucketMap.h:407
const aims::PythonHeader & header() const
Definition: bucket.h:147
std::map< int, std::list< AimsBucketItem< T > > >::key_type key_type
Definition: bucket.h:78
void erase()
Empty the whole map.
Definition: bucket.h:334
std::map< int, std::list< AimsBucketItem< T > > >::iterator iterator
Definition: bucket.h:73
void setSizeZ(float sizez)
sets the Z resolution of the data in mm
Definition: bucket.h:285
An alternate, ordered, representation for buckets (voxels lists).
Definition: bucketMap.h:99
Attributed python-like header, stores all needed information about an object, currently used for volu...
Definition: pheader.h:52
static std::string dataType()
Definition: bucket.h:170
static std::string objectType()
Definition: bucket.h:168
std::string name()
std::string dataType()
The class for EcatSino data write operation.
Definition: borderfiller.h:13