cartodata  4.7.0
siteIterator.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 #ifndef CARTODATA_ROI_SITEITERATOR_H
35 #define CARTODATA_ROI_SITEITERATOR_H
36 
38 #include <soma-io/io/reader.h>
40 #include <vector>
41 #include <iostream>
42 
43 namespace carto
44 {
45 
46 class Site : virtual public RCObject
47 {
48 public:
49 
50  virtual ~Site();
51 
52  Site& operator = ( const Site &other );
53 
54  virtual int size() const = 0;
55  virtual double at( int index ) const = 0;
56  virtual void set( int index, double value ) = 0;
57 
58  bool operator == (const Site &s1);
59  bool operator != (const Site &s1);
60  void write();
61 
62 }; // Site
63 
64 class SiteIterator : public virtual RCObject
65 {
66 public:
67  virtual ~SiteIterator();
68  virtual void next() = 0;
69  virtual void restart() = 0;
70  virtual bool isValid() const = 0;
71  virtual rc_ptr<Site> getSite() = 0;
72  virtual void writeSite() = 0;
73 };
74 
75 template <class T>
76 class SiteIteratorOf : public virtual SiteIterator
77 {
78 };
79 
80 
81 
82 template <class T>
83 class SiteIteratorOf< Volume<T> > : public virtual SiteIterator
84 {
85  VolumeRef<T> _data; // labeled volume
86  int _current[3]; // current coord
87  T _label; // which label to use ?
88  bool _useLabel; // false: ROI = Volume(!=0)
89 
90 public:
92  SiteIteratorOf( VolumeRef<T> data, const T &label);
93  SiteIteratorOf( const std::string &filename);
94  SiteIteratorOf( const std::string &filename, const T &label);
95 
96  virtual ~SiteIteratorOf();
97 
98  virtual void next();
99  virtual void restart();
100  virtual bool isValid() const;
101  // virtual rc_ptr<Site> getSite();
102  virtual void writeSite();
103 };
104 
105 
106 template <class T>
109  _data(data), _useLabel(false)
110 {
111  restart();
112 }
113 
114 
115 template <class T>
117 SiteIteratorOf( VolumeRef<T> data, const T &label ) :
118  _data(data), _label(label), _useLabel(true)
119 {
120  restart();
121 }
122 
123 template <class T>
125 SiteIteratorOf( const std::string &filename ) :
126  _data( new Volume<T> ), _useLabel(false)
127 
128 {
129  Reader< Volume<T> > reader(filename);
130  reader.read(_data);
131  restart();
132 }
133 
134 
135 template <class T>
137 SiteIteratorOf( const std::string &filename, const T &label ) :
138  _data( new Volume<T> ), _label(label), _useLabel(true)
139 {
140  Reader< Volume<T> > reader(filename);
141  reader.read(_data);
142  restart();
143 }
144 
145 template <class T>
146 SiteIteratorOf< Volume<T> >::~SiteIteratorOf()
147 {
148 }
149 
150 
151 template <class T>
153 {
154  _current[ 0 ] = _current[ 1 ] = _current[ 2 ] = 0;
155  if ( isValid() && ( _useLabel ?
156  (*_data)( _current[0], _current[1], _current[2]) != (T) _label :
157  ! (*_data)( _current[0], _current[1], _current[2] ) ) ) next();
158 }
159 
160 
161 template <class T>
163 {
164  do {
165  ++_current[ 0 ];
166  if ( _current[ 0 ] == _data->getSizeX() ) {
167  _current[ 0 ] = 0;
168  ++_current[ 1 ];
169  if ( _current[ 1 ] == _data->getSizeY() ) {
170  _current[ 1 ] = 0;
171  ++_current[ 2 ];
172  }
173  }
174  } while( isValid() && ( _useLabel ?
175  (*_data)( _current[0], _current[1], _current[2]) != (T) _label :
176  ! (*_data)( _current[0], _current[1], _current[2] ) ) );
177 }
178 
179 
180 template <class T>
182 {
183  return _current[ 2 ] < _data->getSizeZ();
184 }
185 
186 /*
187 template <class T>
188 rc_ptr<iSite> SiteIteratorOf< Volume<T> >::getSite()
189 {
190 
191  return rc_ptr<iSite>(new iSite(_current[0], _current[1],_current[2] ));
192 }
193 */
194 
195 template <class T>
197 {
198  std::cout <<""<< _current[0]<<" "<<_current[1]<<" "<<_current[2]<<std::endl;
199 
200 }
201 
202 } //namespace carto
203 
204 
205 #endif // ifndef CARTODATA_ROI_ROI_H
virtual int size() const =0
N-D Volume main class.
bool operator!=(const Site &s1)
virtual double at(int index) const =0
virtual void writeSite()=0
Convenient handle for a Volume - this is normally the entry point for all volumes handling...
Site & operator=(const Site &other)
virtual bool isValid() const =0
virtual ~Site()
virtual void restart()=0
bool operator==(const Site &s1)
void write()
virtual void next()=0