aimsdata  5.1.2
Neuroimaging data handling
flip.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  * Flip data.
36  */
37 #ifndef AIMS_UTILITY_FLIP_H
38 #define AIMS_UTILITY_FLIP_H
39 
43 
44 
49 template <class T>
50 class AimsFlip
51 {
52 public:
56  AimsFlip() { }
58  virtual ~AimsFlip() { }
60 
65  const carto::rc_ptr<carto::Volume<T> > &thing );
68  const carto::rc_ptr<carto::Volume<T> > &thing );
71  const carto::rc_ptr<carto::Volume<T> > &thing );
74  const carto::rc_ptr<carto::Volume<T> > &thing );
77  const carto::rc_ptr<carto::Volume<T> > &thing );
80  const carto::rc_ptr<carto::Volume<T> > &thing );
83  const carto::rc_ptr<carto::Volume<T> > &thing );
86  const carto::rc_ptr<carto::Volume<T> > &thing );
89  const carto::rc_ptr<carto::Volume<T> > &thing );
92  const carto::rc_ptr<carto::Volume<T> > &thing );
94 };
95 
96 
97 template <class T> inline
99  const carto::rc_ptr<carto::Volume<T> > &thing )
100 {
101  carto::VolumeRef<T> res( thing->getSize(), thing->getBorders() );
102  res.copyHeaderFrom( thing->header() );
103 
104  carto::line_NDIterator<T> it( &res->at( 0 ), res->getSize(),
105  res->getStrides() );
106  T *p, *pp;
107  std::vector<int> pos;
108 
109  for( ; !it.ended(); ++it )
110  {
111  p=&*it;
112  pos = it.position();
113  pos[0] = thing->getSizeX() - 1;
114  for( pp=p + it.line_length(); p!=pp; it.inc_line_ptr( p ), --pos[0] )
115  *p = thing->at( pos );
116  }
117 
118  return res;
119 }
120 
121 
122 template <class T> inline
124 {
125  carto::VolumeRef<T> res( thing->getSizeX(), thing->getSizeY(),
126  thing->getSizeZ(), thing->getSizeT(),
127  thing->getBorders() );
128  res.copyHeaderFrom( thing->header() );
129 
130  carto::line_NDIterator<T> it( &res->at( 0 ), res->getSize(),
131  res->getStrides() );
132  T *p, *pp;
133  std::vector<int> pos;
134 
135  for( ; !it.ended(); ++it )
136  {
137  p=&*it;
138  pos = it.position();
139  pos[1] = thing->getSizeY() - pos[1] - 1;
140  for( pp=p + it.line_length(); p!=pp; it.inc_line_ptr( p ), ++pos[0] )
141  *p = thing->at( pos );
142  }
143 
144  return res;
145 }
146 
147 
148 template <class T> inline
150 {
151  carto::VolumeRef<T> res( thing->getSizeX(), thing->getSizeY(),
152  thing->getSizeZ(), thing->getSizeT(),
153  thing->getBorders() );
154  res.copyHeaderFrom( thing->header() );
155 
156  carto::line_NDIterator<T> it( &res->at( 0 ), res->getSize(),
157  res->getStrides() );
158  T *p, *pp;
159  std::vector<int> pos;
160 
161  for( ; !it.ended(); ++it )
162  {
163  p=&*it;
164  pos = it.position();
165  pos[2] = thing->getSizeZ() - pos[2] - 1;
166  for( pp=p + it.line_length(); p!=pp; it.inc_line_ptr( p ), ++pos[0] )
167  *p = thing->at( pos );
168  }
169 
170  return res;
171 }
172 
173 
174 template <class T> inline
176 {
177  carto::VolumeRef<T> res( thing->getSizeX(), thing->getSizeY(),
178  thing->getSizeZ(), thing->getSizeT(),
179  thing->getBorders() );
180  res.copyHeaderFrom( thing->header() );
181 
182  carto::line_NDIterator<T> it( &res->at( 0 ), res->getSize(),
183  res->getStrides() );
184  T *p, *pp;
185  std::vector<int> pos;
186 
187  for( ; !it.ended(); ++it )
188  {
189  p=&*it;
190  pos = it.position();
191  pos[0] = thing->getSizeX() - 1;
192  pos[2] = thing->getSizeZ() - pos[2] - 1;
193  for( pp=p + it.line_length(); p!=pp; it.inc_line_ptr( p ), --pos[0] )
194  *p = thing->at( pos );
195  }
196 
197  return res;
198 }
199 
200 template <class T> inline
202 {
203  carto::VolumeRef<T> res( thing->getSizeX(), thing->getSizeY(),
204  thing->getSizeZ(), thing->getSizeT(),
205  thing->getBorders() );
206  res.copyHeaderFrom( thing->header() );
207 
208  carto::line_NDIterator<T> it( &res->at( 0 ), res->getSize(),
209  res->getStrides() );
210  T *p, *pp;
211  std::vector<int> pos;
212 
213  for( ; !it.ended(); ++it )
214  {
215  p=&*it;
216  pos = it.position();
217  pos[0] = thing->getSizeX() - 1;
218  pos[1] = thing->getSizeY() - pos[1] - 1;
219  for( pp=p + it.line_length(); p!=pp; it.inc_line_ptr( p ), --pos[0] )
220  *p = thing->at( pos );
221  }
222 
223  return res;
224 }
225 
226 
227 template <class T> inline
229 {
230  carto::VolumeRef<T> res( thing->getSizeX(), thing->getSizeY(),
231  thing->getSizeZ(), thing->getSizeT(),
232  thing->getBorders() );
233  res.copyHeaderFrom( thing->header() );
234 
235  carto::line_NDIterator<T> it( &res->at( 0 ), res->getSize(),
236  res->getStrides() );
237  T *p, *pp;
238  std::vector<int> pos;
239 
240  for( ; !it.ended(); ++it )
241  {
242  p=&*it;
243  pos = it.position();
244  pos[1] = thing->getSizeY() - pos[1] - 1;
245  pos[2] = thing->getSizeZ() - pos[2] - 1;
246  for( pp=p + it.line_length(); p!=pp; it.inc_line_ptr( p ), ++pos[0] )
247  *p = thing->at( pos );
248  }
249 
250  return res;
251 }
252 
253 
254 template <class T> inline
256 {
257  carto::VolumeRef<T> res( thing->getSizeY(), thing->getSizeX(),
258  thing->getSizeZ(), thing->getSizeT(),
259  thing->getBorders() );
260  res.copyHeaderFrom( thing->header() );
261  std::vector<float> vs = thing->getVoxelSize();
262  float t = vs[0];
263  vs[0] = vs[1];
264  vs[1] = t;
265  res.setVoxelSize( vs );
266 
267  carto::line_NDIterator<T> it( &res->at( 0 ), res->getSize(),
268  res->getStrides() );
269  T *p, *pp;
270  std::vector<int> pos;
271 
272  for( ; !it.ended(); ++it )
273  {
274  p=&*it;
275  pos = it.position();
276  pos[0] = res->getSizeY() - pos[1] - 1;
277  pos[1] = res->getSizeX() - 1;
278  for( pp=p + it.line_length(); p!=pp; it.inc_line_ptr( p ), --pos[1] )
279  *p = thing->at( pos );
280  }
281 
282  return res;
283 }
284 
285 
286 template <class T> inline
288  const carto::rc_ptr<carto::Volume<T> > &thing )
289 {
290  carto::VolumeRef<T> res( thing->getSizeZ(), thing->getSizeY(),
291  thing->getSizeX(), thing->getSizeT(),
292  thing->getBorders() );
293  res.copyHeaderFrom( thing->header() );
294  std::vector<float> vs = thing->getVoxelSize();
295  float t = vs[0];
296  vs[0] = vs[2];
297  vs[2] = t;
298  res.setVoxelSize( vs );
299 
300  carto::line_NDIterator<T> it( &res->at( 0 ), res->getSize(),
301  res->getStrides() );
302  T *p, *pp;
303  std::vector<int> pos;
304 
305  for( ; !it.ended(); ++it )
306  {
307  p=&*it;
308  pos = it.position();
309  pos[0] = res->getSizeZ() - pos[2] - 1;
310  pos[2] = res->getSizeX() - 1;
311  for( pp=p + it.line_length(); p!=pp; it.inc_line_ptr( p ), --pos[2] )
312  *p = thing->at( pos );
313  }
314 
315  return res;
316 }
317 
318 
319 template <class T> inline
321  const carto::rc_ptr<carto::Volume<T> > &thing )
322 {
323  carto::VolumeRef<T> res( thing->getSizeX(), thing->getSizeZ(),
324  thing->getSizeY(), thing->getSizeT(),
325  thing->getBorders() );
326  res.copyHeaderFrom( thing->header() );
327  std::vector<float> vs = thing->getVoxelSize();
328  float t = vs[1];
329  vs[1] = vs[2];
330  vs[2] = t;
331  res.setVoxelSize( vs );
332 
333  carto::line_NDIterator<T> it( &res->at( 0 ), res->getSize(),
334  res->getStrides() );
335  T *p, *pp;
336  std::vector<int> pos;
337  int x;
338 
339  for( ; !it.ended(); ++it )
340  {
341  p=&*it;
342  pos = it.position();
343  x = pos[1];
344  pos[1] = res->getSizeZ() - pos[2] - 1;
345  pos[2] = res->getSizeY() - x - 1;
346  for( pp=p + it.line_length(); p!=pp; it.inc_line_ptr( p ), ++pos[0] )
347  *p = thing->at( pos );
348  }
349 
350  return res;
351 }
352 
353 
354 template <class T> inline
356  const carto::rc_ptr<carto::Volume<T> > &thing )
357 {
358  carto::VolumeRef<T> res( thing->getSize(), thing->getBorders() );
359  res.copyHeaderFrom( thing->header() );
360 
361  carto::line_NDIterator<T> it( &res->at( 0 ), res->getSize(),
362  res->getStrides() );
363  T *p, *pp;
364  std::vector<int> pos;
365 
366  for( ; !it.ended(); ++it )
367  {
368  p=&*it;
369  pos = it.position();
370  pos[0] = thing->getSizeX() - 1;
371  pos[1] = thing->getSizeY() - pos[1] - 1;
372  pos[2] = thing->getSizeZ() - pos[2] - 1;
373  for( pp=p + it.line_length(); p!=pp; it.inc_line_ptr( p ), --pos[0] )
374  *p = thing->at( pos );
375  }
376 
377  return res;
378 }
379 
380 
381 #endif
The template object function for flipping.
Definition: flip.h:51
carto::VolumeRef< T > doZZ(const carto::rc_ptr< carto::Volume< T > > &thing)
function which returns the ZZ flipped data
Definition: flip.h:149
carto::VolumeRef< T > doYY(const carto::rc_ptr< carto::Volume< T > > &thing)
function which returns the YY flipped data
Definition: flip.h:123
AimsFlip()
Constructor does nothing.
Definition: flip.h:56
carto::VolumeRef< T > doXX(const carto::rc_ptr< carto::Volume< T > > &thing)
function which returns the XX flipped data
Definition: flip.h:98
carto::VolumeRef< T > doXZ(const carto::rc_ptr< carto::Volume< T > > &thing)
function which returns the XZ flipped data
Definition: flip.h:287
carto::VolumeRef< T > doXXYYZZ(const carto::rc_ptr< carto::Volume< T > > &thing)
function which returns the XXYYZZ flipped data
Definition: flip.h:355
carto::VolumeRef< T > doXY(const carto::rc_ptr< carto::Volume< T > > &thing)
function which returns the XY flipped data
Definition: flip.h:255
carto::VolumeRef< T > doXXZZ(const carto::rc_ptr< carto::Volume< T > > &thing)
function which returns the XXZZ flipped data
Definition: flip.h:175
virtual ~AimsFlip()
Destructor does nothing.
Definition: flip.h:58
carto::VolumeRef< T > doYZ(const carto::rc_ptr< carto::Volume< T > > &thing)
function which returns the YZ flipped data
Definition: flip.h:320
carto::VolumeRef< T > doYYZZ(const carto::rc_ptr< carto::Volume< T > > &thing)
function which returns the YYZZ flipped data
Definition: flip.h:228
carto::VolumeRef< T > doXXYY(const carto::rc_ptr< carto::Volume< T > > &thing)
function which returns the XXYY flipped data
Definition: flip.h:201
const std::vector< int > & position() const
int getSizeZ() const
void setVoxelSize(float vx, float vy=1., float vz=1., float vt=1.)
virtual void copyHeaderFrom(const PropertySet &other)
std::vector< int > getSize() const
const T & at(long x, long y=0, long z=0, long t=0) const
int getSizeY() const
int getSizeX() const
std::vector< size_t > getStrides() const
long line_length() const
void inc_line_ptr(T *&p) const