aimsdata 6.0.0
Neuroimaging data handling
bucketMap.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_BUCKETMAP_H
38#define AIMS_BUCKET_BUCKETMAP_H
39
40#include <cartobase/object/object.h>
42#include <aims/bucket/bucket.h>
43#include <aims/math/dtitensor.h>
44#include <cartobase/type/types.h>
45#include <iostream>
46#include <map>
47
48
49namespace aims
50{
51 template <class T> class BucketMap;
52 //typedef BucketMap<short> BucketMapShort ;
53
54
56 template <class T, int D>
58 {};
59
60 // Specialization
61 template <class T>
62 struct CoordinatesLess<T, 3>: public std::binary_function<T, T, bool>
63 {
64 bool operator () ( const T & p1, const T & p2 ) const
65 {
66 return p1[2] < p2[2]
67 || ( p1[2] == p2[2]
68 && ( p1[1] < p2[1]
69 || ( p1[1] == p2[1] && ( p1[0] < p2[0] ) ) ) );
70 }
71 };
72
74// /// Helper class for ordering Point3d by their z, y, x coordinates
75// struct BucketMapLess : public std::binary_function<Point3d, Point3d, bool>
76// {
77// bool operator () ( const Point3d & p1, const Point3d & p2 ) const
78// {
79// return p1[2] < p2[2]
80// || ( p1[2] == p2[2]
81// && ( p1[1] < p2[1]
82// || ( p1[1] == p2[1] && ( p1[0] < p2[0] ) ) ) );
83// }
84// };
85
86
95 template <class T>
97 : public virtual carto::RCObject,
98 public std::map< int , std::map< Point3d, T, BucketMapLess > >
99 {
100 public:
101 typedef std::map< int , std::map< Point3d, T, BucketMapLess > > BaseMap;
102 typedef std::map< Point3d, T, BucketMapLess > Bucket;
103 typedef typename std::map<int, Bucket >::iterator iterator;
104 typedef typename std::map<int, Bucket >::const_iterator const_iterator;
105
106 BucketMap() : std::map< int , Bucket >()
107 { }
108 BucketMap( const BucketMap<T> & other )
109 : RCObject(), std::map< int , Bucket >( other ), _header( other._header )
110 { }
111
113 virtual ~BucketMap() { }
114
115 BucketMap<T> & operator = ( const AimsBucket<T> & );
117 inline void insert( const Point3d & pos, const T & item );
119 inline void insert( const std::pair<const Point3d,T> & item );
120 using BaseMap::insert; // make overloads from std::map visible
121
123 inline void erase( const Point3d & pos );
124 using BaseMap::erase; // make overloads from std::map visible
125
126 inline void merge( const BucketMap<T> & );
127
129 inline float sizeX() const;
131 inline float sizeY() const;
133 inline float sizeZ() const;
135 inline float sizeT() const;
136 inline std::vector<float> getVoxelSize() const;
137
139 inline void setSizeX(float sizex);
141 inline void setSizeY(float sizey);
143 inline void setSizeZ(float sizez);
145 inline void setSizeT(float sizet);
147 inline void setSizeXYZT( float sizex,float sizey,float sizez,float sizet );
148 inline void setSizeXYZT( const std::vector<float> & vsize );
149 inline void setVoxelSize( float sizex, float sizey, float sizez,
150 float sizet )
151 { setSizeXYZT( sizex, sizey, sizez, sizet ); }
152 inline void setVoxelSize( const std::vector<float> & vsize )
153 { setSizeXYZT( vsize ); }
154
155 inline const aims::PythonHeader &header() const { return _header; }
156 inline aims::PythonHeader &header() { return _header; }
157 void setHeader( const aims::PythonHeader &hdr ) { _header = hdr; }
158
159 protected:
161 };
162
163}
164
165
166
167#ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
168
169namespace carto
170{
171
172 template<class T> class DataTypeCode<aims::BucketMap<T> >
173 {
174 public:
175 static std::string objectType()
176 { return "Bucket"; }
177 static std::string dataType()
178 { return DataTypeCode<T>::dataType(); }
179 static std::string name()
180 {
181 return std::string("bucket of ") + DataTypeCode< T >::name();
182 }
183 };
184
185}
186
187#endif // DOXYGEN_HIDE_INTERNAL_CLASSES
188
189
190namespace aims
191{
192
193 template <class T> inline
194 void BucketMap<T>::insert( const Point3d & pos, const T & item )
195 {
196 (*this)[0][pos] = item;
197 }
198
199
200 template <class T> inline
201 void BucketMap<T>::insert( const std::pair<const Point3d, T> & item )
202 {
203 (*this)[0].insert(item);
204 }
205
206
207 template <class T> inline
208 void BucketMap<T>::erase( const Point3d & pos )
209 {
210 (*this)[0].erase( pos );
211 }
212
213
214 template <class T> inline
216 {
217 typename BucketMap<T>::const_iterator i, e = bck.end();
218 for( i=bck.begin(); i!=e; ++i )
219 (*this)[ i->first ].insert( i->second.begin(), i->second.end() );
220 }
221
222
223 template <class T> inline std::vector<float>
225 {
226 std::vector<float> vs;
227 _header.getProperty( "voxel_size", vs );
228 while( vs.size() < 4 )
229 vs.push_back( 1. );
230 return vs;
231 }
232
233
234 template <class T> inline float BucketMap<T>::sizeX() const
235 {
236 std::vector<float> vs;
237 _header.getProperty( "voxel_size", vs );
238 if( vs.empty() )
239 return 1.;
240 return vs[0];
241 }
242
243
244 template <class T> inline float BucketMap<T>::sizeY() const
245 {
246 std::vector<float> vs;
247 _header.getProperty( "voxel_size", vs );
248 if( vs.size() < 2 )
249 return 1.;
250 return vs[1];
251 }
252
253
254 template <class T> inline float BucketMap<T>::sizeZ() const
255 {
256 std::vector<float> vs;
257 _header.getProperty( "voxel_size", vs );
258 if( vs.size() < 3 )
259 return 1.;
260 return vs[2];
261 }
262
263
264 template <class T> inline float BucketMap<T>::sizeT() const
265 {
266 std::vector<float> vs;
267 _header.getProperty( "voxel_size", vs );
268 if( vs.size() < 4 )
269 return 1.;
270 return vs[3];
271 }
272
273
274 template <class T> inline
275 void BucketMap<T>::setSizeX(float sizex)
276 {
277 ASSERT(sizex>0);
278 std::vector<float> vs;
279 _header.getProperty( "voxel_size", vs );
280 while( vs.size() < 4 )
281 vs.push_back( 1. );
282 vs[0] = sizex;
283 _header.setProperty( "voxel_size", vs );
284 }
285
286
287 template <class T> inline
288 void BucketMap<T>::setSizeY(float sizey)
289 {
290 ASSERT(sizey>0);
291 std::vector<float> vs;
292 _header.getProperty( "voxel_size", vs );
293 while( vs.size() < 4 )
294 vs.push_back( 1. );
295 vs[1] = sizey;
296 _header.setProperty( "voxel_size", vs );
297 }
298
299
300 template <class T> inline
301 void BucketMap<T>::setSizeZ(float sizez)
302 {
303 ASSERT(sizez>0);
304 std::vector<float> vs;
305 _header.getProperty( "voxel_size", vs );
306 while( vs.size() < 4 )
307 vs.push_back( 1. );
308 vs[2] = sizez;
309 _header.setProperty( "voxel_size", vs );
310 }
311
312
313 template <class T> inline
314 void BucketMap<T>::setSizeT(float sizet)
315 {
316 ASSERT(sizet>0);
317 std::vector<float> vs;
318 _header.getProperty( "voxel_size", vs );
319 while( vs.size() < 4 )
320 vs.push_back( 1. );
321 vs[3] = sizet;
322 _header.setProperty( "voxel_size", vs );
323 }
324
325
326 template <class T> inline
327 void BucketMap<T>::setSizeXYZT( float sizex, float sizey, float sizez,
328 float sizet)
329 {
330 std::vector<float> vs(4);
331 vs[0] = sizex;
332 vs[1] = sizey;
333 vs[2] = sizez;
334 vs[3] = sizet;
335 _header.setProperty( "voxel_size", vs );
336 }
337
338
339 template <class T> inline
340 void BucketMap<T>::setSizeXYZT( const std::vector<float> & vsize )
341 {
342 std::vector<float> vs = vsize;
343 while( vs.size() < 4 )
344 vs.push_back( 1. );
345 _header.setProperty( "voxel_size", vs );
346 }
347
348
349 template<class T> inline
351 : _header( other.header() )
352 {
353 *this = other;
354 }
355
356
357 template<class T> inline BucketMap<T> &
359 {
360 this->clear();
361 typename AimsBucket<T>::const_iterator ib, eb = other.end();
362 typename std::list<AimsBucketItem<T> >::const_iterator ibi, ebi;
363
364 for ( ib=other.begin(); ib!=eb; ++ib )
365 {
366 Bucket & bk = (*this)[ ib->first ];
367 for ( ibi=ib->second.begin(), ebi=ib->second.end(); ibi!=ebi; ++ibi )
368 bk[ ibi->location() ] = ibi->value();
369 }
370 _header = other.header();
371 return *this;
372 }
373
374
375}
376
377template <class T> inline
378std::ostream& operator << (std::ostream& out, const aims::BucketMap<T> & thing)
379{
380 out << "{";
381
382 typename aims::BucketMap<T>::const_iterator it1, e1 = thing.end();
383
384 for ( it1=thing.begin(); it1!=e1; ++it1 )
385 {
386 typename aims::BucketMap<T>::Bucket::const_iterator it2 , e2 = it1->second.end();
387 out << "{";
388 out << "t=" << (*it1).first << ",";
389 for ( it2=it1->second.begin(); it2!=e2; ++it2 )
390 out << *it2 << ",";
391 out << "NULL},";
392 }
393
394 return out << "NULL}" << std::flush;
395}
396
397// Implementation of some AimsBucket conversion functions
398
399template<class T> inline
401{
402 *this = b2;
403}
404
405
406template<class T> inline AimsBucket<T> &
408{
409 this->clear();
410 typename aims::BucketMap<T>::const_iterator ib, eb = b2.end();
411 typename aims::BucketMap<T>::Bucket::const_iterator ibi, ebi;
412 AimsBucketItem<T> bitem;
413
414 for ( ib=b2.begin(); ib!=eb; ++ib )
415 {
416 std::list<AimsBucketItem<T> > & bk = (*this)[ ib->first ];
417 for ( ibi=ib->second.begin(), ebi=ib->second.end(); ibi!=ebi; ++ibi )
418 {
419 bitem.location() = ibi->first;
420 bitem.value() = ibi->second;
421 bk.push_back( bitem );
422 }
423 }
424 _header = b2.header();
425 return *this;
426}
427
428namespace carto {
429
438
440DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< aims::BucketMap<int16_t> > )
441DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< aims::BucketMap<uint16_t> > )
442DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< aims::BucketMap<int32_t> > )
443DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< aims::BucketMap<uint32_t> > )
444DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< aims::BucketMap<float> > )
445DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< aims::BucketMap<double> > )
446DECLARE_GENERIC_OBJECT_TYPE( rc_ptr< aims::BucketMap<DtiTensor> > )
447
448} // namespace carto
449
450#endif
#define AIMSDATA_API
#define ASSERT(EX)
std::ostream & operator<<(std::ostream &out, const aims::BucketMap< T > &thing)
Definition bucketMap.h:378
The template base class for all types of bucket items.
Definition item.h:63
const T & value() const
Get a const reference to the value of the bucket item.
Definition item.h:87
const AimsVector< short, 3 > & location() const
Get a const reference to the location of the bucket item.
Definition item.h:92
The bucket base class to manage packages of points associated to their value during time.
Definition bucket.h:70
AimsBucket()
Definition bucket.h:80
aims::PythonHeader _header
Definition bucket.h:156
AimsBucket< T > & operator=(const aims::BucketMap< T > &)
Definition bucketMap.h:407
std::map< int, std::list< AimsBucketItem< T > > >::const_iterator const_iterator
Definition bucket.h:76
const aims::PythonHeader & header() const
Definition bucket.h:147
An alternate, ordered, representation for buckets (voxels lists).
Definition bucketMap.h:99
float sizeZ() const
returns the Z resolution in mm
Definition bucketMap.h:254
void setSizeX(float sizex)
sets the X resolution of the data in mm
Definition bucketMap.h:275
void setVoxelSize(const std::vector< float > &vsize)
Definition bucketMap.h:152
std::map< int, Bucket >::const_iterator const_iterator
Definition bucketMap.h:104
void setSizeY(float sizey)
sets the Y resolution of the data in mm
Definition bucketMap.h:288
void insert(const Point3d &pos, const T &item)
Function redefined to omit time.
Definition bucketMap.h:194
const aims::PythonHeader & header() const
Definition bucketMap.h:155
void setSizeXYZT(float sizex, float sizey, float sizez, float sizet)
sets X,Y,Z and T resolutions of the data
Definition bucketMap.h:327
aims::PythonHeader & header()
Definition bucketMap.h:156
BucketMap(const BucketMap< T > &other)
Definition bucketMap.h:108
void merge(const BucketMap< T > &)
Definition bucketMap.h:215
void erase(const Point3d &pos)
Function redefined to omit time.
Definition bucketMap.h:208
std::map< int, std::map< Point3d, T, BucketMapLess > > BaseMap
Definition bucketMap.h:101
std::map< Point3d, T, BucketMapLess > Bucket
Definition bucketMap.h:102
float sizeT() const
returns the T resolution in s
Definition bucketMap.h:264
float sizeY() const
returns the Y resolution in mm
Definition bucketMap.h:244
std::map< int, Bucket >::iterator iterator
Definition bucketMap.h:103
void insert(const std::pair< const Point3d, T > &item)
Function redefined to omit time, looks more like STL maps.
Definition bucketMap.h:201
BucketMap< T > & operator=(const AimsBucket< T > &)
Definition bucketMap.h:358
void setVoxelSize(float sizex, float sizey, float sizez, float sizet)
Definition bucketMap.h:149
void setHeader(const aims::PythonHeader &hdr)
Definition bucketMap.h:157
aims::PythonHeader _header
Definition bucketMap.h:160
virtual ~BucketMap()
Definition bucketMap.h:113
void setSizeZ(float sizez)
sets the Z resolution of the data in mm
Definition bucketMap.h:301
float sizeX() const
returns the X resolution in mm
Definition bucketMap.h:234
void setSizeXYZT(const std::vector< float > &vsize)
Definition bucketMap.h:340
std::vector< float > getVoxelSize() const
Definition bucketMap.h:224
void setSizeT(float sizet)
sets the T resolution of the data in s
Definition bucketMap.h:314
BucketMap(const AimsBucket< T > &)
build from AimsBucket
Definition bucketMap.h:350
Attributed python-like header, stores all needed information about an object, currently used for volu...
Definition pheader.h:52
std::string name()
std::string dataType()
The class for EcatSino data write operation.
CoordinatesLess< Point3d, 3 > BucketMapLess
Definition bucketMap.h:73
STL namespace.
#define DECLARE_GENERIC_OBJECT_TYPE(T)
Helper class for ordering Coordinates by their z, y, x coordinates.
Definition bucketMap.h:58
AimsVector< int16_t, 3 > Point3d