aimsdata 6.0.0
Neuroimaging data handling
roiIterator.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_ROI_ROIITERATOR_H
36#define AIMS_ROI_ROIITERATOR_H
37
39#include <cartobase/smart/rcptr.h>
40#include <aims/io/reader.h>
41#include <set>
42#include <string>
43
44namespace aims
45{
46
47 //---------------------------------------------------------------------------
49 {
50 public:
51
52 virtual ~ROILabelMap() {}
53
54 virtual int32_t at( const Point3df & ) const = 0;
55 std::vector< std::string > roiNames;
56 };
57
58
59 //---------------------------------------------------------------------------
61 {
62 public:
63
65 virtual ~VolumeROILabelMap() {}
66
67 virtual int32_t at( const Point3df & ) const;
68
69 private:
71 };
72
73
74 //---------------------------------------------------------------------------
76 {
77 public:
78
81
82 virtual int32_t at( const Point3df & ) const;
83
84 private:
85
86 const AffineTransformation3d _motion;
87 };
88
89
90 //---------------------------------------------------------------------------
92 {
93 public:
94 virtual ~RoiIterator() {}
95
96 virtual bool isValid() const = 0;
97 virtual void restart() = 0;
98 virtual size_t count() const = 0;
99
100 virtual void next() = 0;
102 inline const Point3d volumeDimension() const;
103 inline const Point3df voxelSize() const;
104 inline float voxelVolume() const;
105 virtual std::string regionName() const = 0;
113 virtual void setRegionNameAttributes( const std::vector<std::string>& ) {}
117 virtual void setRegionNameAttributes( const std::string & );
118
119
121 };
122
123
124 //---------------------------------------------------------------------------
126 {
127 public:
129 const AffineTransformation3d & );
131
132 virtual bool isValid() const;
133 virtual void restart();
134 virtual size_t count() const;
135
136 virtual void next();
138 inline const Point3d volumeDimension() const;
139 inline const Point3df voxelSize() const;
140 inline float voxelVolume() const;
141 virtual std::string regionName() const;
142 virtual void setRegionNameAttributes( const std::vector<std::string>& );
143
145
146 protected:
149 };
150
151
152 //---------------------------------------------------------------------------
154 {
155 return maskIterator()->volumeDimension();
156 }
157
158 //---------------------------------------------------------------------------
159 inline const Point3df RoiIterator::voxelSize() const
160 {
161 return maskIterator()->voxelSize();
162 }
163
164 //---------------------------------------------------------------------------
165 inline float RoiIterator::voxelVolume() const
166 {
167 return maskIterator()->voxelVolume();
168 }
169
170 //---------------------------------------------------------------------------
171 template <class T>
173 {
174 };
175
176
177 //---------------------------------------------------------------------------
178 template <>
180 {
181 const Graph *_roi;
182 carto::rc_ptr< Graph > _roiLife;
183 std::set< std::string > _names;
184 std::set< std::string >::const_iterator _itNames;
185 carto::rc_ptr< VoxelSampler > _voxelSampler;
186 std::vector<std::string> _nameAttributes;
187
188 public:
189
190 RoiIteratorOf( const Graph &roi,
191 carto::rc_ptr< VoxelSampler > voxelSampler =
194 carto::rc_ptr< VoxelSampler > voxelSampler =
196 RoiIteratorOf( const std::string &fileName,
197 carto::rc_ptr< VoxelSampler > voxelSampler =
199 virtual ~RoiIteratorOf();
200
201 virtual bool isValid() const;
202 virtual void restart();
203 virtual size_t count() const;
204
212 virtual void setRegionNameAttributes( const std::vector<std::string>
213 & attributes );
214 virtual std::string regionName() const;
215
217 virtual void next();
218 };
219
220
221
222 //---------------------------------------------------------------------------
223 template <class T>
224 class RoiIteratorOf< carto::VolumeRef<T> > : public RoiIterator
225 {
226 mutable carto::VolumeRef<T> _data;
227 Point3d _current;
228 typename std::map< T, specifiedLabels > _labels;
229 typename std::map< T, specifiedLabels >::const_iterator _label;
230 carto::rc_ptr< VoxelSampler > _voxelSampler;
231
232 void buildLabels();
233
234 public:
235
237 carto::rc_ptr< VoxelSampler > voxelSampler =
239 RoiIteratorOf( const std::string &fileName,
240 carto::rc_ptr< VoxelSampler > voxelSampler );
241 virtual ~RoiIteratorOf();
242
243 virtual bool isValid() const;
244 virtual void restart();
245 virtual size_t count() const;
246
247 virtual std::string regionName() const;
248
250 virtual void next();
251 };
252
253
254
255
256 //---------------------------------------------------------------------------
257 template <class T>
259 const carto::VolumeRef<T> &data,
260 carto::rc_ptr< VoxelSampler > voxelSampler ) :
261 _data( data ),
262 _voxelSampler( voxelSampler )
263 {
264 buildLabels();
265 restart();
266 }
267
268 //---------------------------------------------------------------------------
269 template <class T>
271 const std::string &fileName, carto::rc_ptr< VoxelSampler > voxelSampler ) :
272 _data(),
273 _voxelSampler( voxelSampler )
274 {
275 Reader< carto::Volume<T> > reader( fileName );
276 _data.reset( reader.read() );
277 buildLabels();
278 restart();
279 }
280
281 //---------------------------------------------------------------------------
282 template <class T>
283 void RoiIteratorOf< carto::VolumeRef<T> >::buildLabels()
284 {
285 Point3d p;
286 typename std::map< T, specifiedLabels >::iterator it;
287
288 for( p[2] = 0; p[2] < _data->getSizeZ(); ++p[2] ) {
289 for( p[1] = 0; p[1] < _data->getSizeY(); ++p[1] ) {
290 for( p[0] = 0; p[0] < _data->getSizeX(); ++p[0] ) {
291 T v = (*_data)( p );
292 // NaN values are considered background like 0 (SPM does so)
293 if ( v && !std::isnan( v ) ) {
294 it = _labels.find( v );
295 _labels[ v ].lastPoint = p;
296
297 if ( it == _labels.end() ) {
298 _labels[ v ].firstPoint = p;
299 }
300 }
301 }
302 }
303 }
304 }
305
306
307 //---------------------------------------------------------------------------
308 template <class T>
312
313
314 //---------------------------------------------------------------------------
315 template <class T>
318 maskIterator() const
319 {
321 ( new MaskIteratorOf< carto::VolumeRef<T> >( _data, _label->second,
322 _voxelSampler ) );
323 }
324
325 //---------------------------------------------------------------------------
326 template <class T>
328 {
329 ++_label;
330 }
331
332
333 //---------------------------------------------------------------------------
334 template <class T>
336 {
337 return _label != _labels.end();
338 }
339
340 //---------------------------------------------------------------------------
341 template <class T>
343 {
344 _label = _labels.begin();
345 }
346
347 //---------------------------------------------------------------------------
348 template <class T>
350 {
351 return _labels.size();
352 }
353
354 //---------------------------------------------------------------------------
355 template <class T>
357 {
358 return carto::toString( _label->first );
359 }
360
361 //---------------------------------------------------------------------------
362 // roiIterator factories (to be continued)
363
364 //---------------------------------------------------------------------------
366 getRoiIterator( const std::string &fileName,
367 carto::rc_ptr< VoxelSampler > voxelSampler =
369
370 //---------------------------------------------------------------------------
371 template <class T>
374 carto::rc_ptr< VoxelSampler > voxelSampler =
376 {
378 ( new RoiIteratorOf< carto::VolumeRef<T> >( data, voxelSampler ) );
379 }
380
381 //---------------------------------------------------------------------------
382 template <class T>
385 carto::rc_ptr< VoxelSampler > voxelSampler =
387 {
389 ( new RoiIteratorOf< carto::VolumeRef<T> >( data, voxelSampler ) );
390 }
391
392 //---------------------------------------------------------------------------
394 getRoiIterator( const Graph &data,
395 carto::rc_ptr< VoxelSampler > voxelSampler =
397
398 //---------------------------------------------------------------------------
399 carto::rc_ptr< RoiIterator > getRoiIterator( const std::string &fileName,
400 const AffineTransformation3d & );
401
402 //---------------------------------------------------------------------------
404 getRoiIterator( const std::string &fileName,
406 const AffineTransformation3d & );
407
408 //---------------------------------------------------------------------------
409 template <class T>
411 const carto::VolumeRef< T > &data, const AffineTransformation3d &motion )
412 {
413 return carto::
414 rc_ptr< RoiIterator >( new MotionedRoiIterator( getRoiIterator( data ),
415 motion ) );
416 }
417
418 //---------------------------------------------------------------------------
419 template <class T>
421 const carto::rc_ptr<carto::Volume< T > > &data, const AffineTransformation3d &motion )
422 {
423 return carto::
424 rc_ptr< RoiIterator >( new MotionedRoiIterator( getRoiIterator( data ),
425 motion ) );
426 }
427
428 //---------------------------------------------------------------------------
430 const AffineTransformation3d &motion ) ;
431
432 //---------------------------------------------------------------------------
433 template <class T>
437 const AffineTransformation3d &motion )
438 {
439 return carto::
440 rc_ptr< RoiIterator >
441 ( new MotionedRoiIterator( getRoiIterator( data, voxelSampler ),
442 motion ) );
443 }
444
445 //---------------------------------------------------------------------------
446 template <class T>
450 const AffineTransformation3d &motion )
451 {
452 return carto::
453 rc_ptr< RoiIterator >
454 ( new MotionedRoiIterator( getRoiIterator( data, voxelSampler ),
455 motion ) );
456 }
457
458 //---------------------------------------------------------------------------
460 getRoiIterator( const Graph &data,
462 const AffineTransformation3d &motion ) ;
463
464 //---------------------------------------------------------------------------
465 extern template class RoiIteratorOf<carto::VolumeRef<int16_t> >;
466 extern template class RoiIteratorOf<Graph>;
467
468} // namespace aims
469
470#endif
const Point3d volumeDimension() const
MotionedRoiIterator(const carto::rc_ptr< RoiIterator > &, const AffineTransformation3d &)
virtual void setRegionNameAttributes(const std::vector< std::string > &)
Set region name attribute in graph.
const AffineTransformation3d _motion
virtual carto::rc_ptr< MaskIterator > maskIterator() const
virtual bool isValid() const
virtual std::string regionName() const
virtual carto::rc_ptr< ROILabelMap > createLabelMap()
const carto::rc_ptr< RoiIterator > _roiIterator
virtual size_t count() const
const Point3df voxelSize() const
virtual int32_t at(const Point3df &) const
MotionedVolumeROILabelMap(carto::VolumeRef< int32_t > &, const AffineTransformation3d &)
virtual ~ROILabelMap()
Definition roiIterator.h:52
std::vector< std::string > roiNames
Definition roiIterator.h:55
virtual int32_t at(const Point3df &) const =0
Generic reader for every format of Aims object.
Definition reader.h:70
virtual bool read(T &obj, int border=0, const std::string *format=0, int frame=-1)
Finds the correct format and reads the object. if format is specified, this format is tried first,...
Definition reader_d.h:142
virtual bool isValid() const
RoiIteratorOf(const std::string &fileName, carto::rc_ptr< VoxelSampler > voxelSampler=carto::rc_ptr< VoxelSampler >())
RoiIteratorOf(const carto::rc_ptr< Graph > &roi, carto::rc_ptr< VoxelSampler > voxelSampler=carto::rc_ptr< VoxelSampler >())
virtual std::string regionName() const
virtual carto::rc_ptr< MaskIterator > maskIterator() const
RoiIteratorOf(const Graph &roi, carto::rc_ptr< VoxelSampler > voxelSampler=carto::rc_ptr< VoxelSampler >())
virtual size_t count() const
virtual void setRegionNameAttributes(const std::vector< std::string > &attributes)
Set region name attribute in graph.
RoiIteratorOf(const carto::VolumeRef< T > &data, carto::rc_ptr< VoxelSampler > voxelSampler=carto::rc_ptr< VoxelSampler >())
virtual std::string regionName() const
virtual size_t count() const =0
float voxelVolume() const
virtual ~RoiIterator()
Definition roiIterator.h:94
virtual void next()=0
virtual void setRegionNameAttributes(const std::vector< std::string > &)
Set region name attribute in graph.
const Point3df voxelSize() const
virtual void setRegionNameAttributes(const std::string &)
Set region name attribute in graph.
virtual void restart()=0
virtual std::string regionName() const =0
virtual carto::rc_ptr< ROILabelMap > createLabelMap()
virtual carto::rc_ptr< MaskIterator > maskIterator() const =0
virtual bool isValid() const =0
const Point3d volumeDimension() const
VolumeROILabelMap(carto::VolumeRef< int32_t > &)
virtual int32_t at(const Point3df &) const
The class for EcatSino data write operation.
carto::rc_ptr< RoiIterator > getRoiIterator(const std::string &fileName, carto::rc_ptr< VoxelSampler > voxelSampler=carto::rc_ptr< VoxelSampler >())
std::string toString(const T &object)
AimsVector< float, 3 > Point3df
AimsVector< int16_t, 3 > Point3d